Re: ObjectAlloc and objects that should have been released

2009-04-24 Thread Alexander Spohr


Am 24.04.2009 um 01:27 schrieb Miles:

But when I run this in ObjectAlloc, a bunch of parts of the view are  
still

showing as 'created and still living'. It's very odd considering the
deallocs are both called so nothing should be hanging around.


What is „a bunch of parts of the view“ in your case? You talk about  
two deallocs but „a bunch“ sounds more than two. Are you sure you  
release all retained vars in your dealloc?

Maybe you have a cross-retain? (if you don’t use the GC).

atze

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: CF autorelease?

2009-04-24 Thread Wade Tregaskis
Another caveat with cleanup is that it is not guaranteed to be  
called.  For this audience, the most likely way this will bite you  
is when the new zero cost objective-c exceptions aren't available  
(i386, ppc) and an exception is thrown.  If zero cost objective-c  
exceptions are available, then the compiler arranges to have the  
cleanup function called during the stack unwind.


There's enough gotchas to cleanup that I definitely wouldn't count  
on it for proper memory management.


Admittedly I wasn't aware of that (it's also not called if you invoke  
exit or abort, but that's kind of expected).  However, exceptions are  
not usually safe to use through vanilla C code anyway, whether CF- 
based or otherwise, so that's a moot point (if you were using C++, you  
could use the template Peter Lewis suggested, and if you're using ObjC  
you can just autorelease directly).  Good that you pointed it out  
though.


Wade
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Problem implementing keyPathsForvaluesAffectingKey

2009-04-24 Thread jonat...@mugginsoft.com


On 23 Apr 2009, at 23:21, Jim Correia wrote:


On Apr 22, 2009, at 10:45 AM, jonat...@mugginsoft.com wrote:

The property canDelete is dependent on three other properties as  
shown below.


Is there a problem with my implementation of  +  
keyPathsForValuesAffectingCanDelete with regard to the key path  
@arrayController.canRemove?


Is is a relatively well known issue that  
NSKeyValueObservingOptionNew and NSKeyValueObservingOptionOld do not  
work with controller properties. See:


http://homepage.mac.com/mmalc/CocoaExamples/controllers.html

What is perhaps less well known is that controller keys which don't  
support the New/Old KVO observing options also don't support  
NSKeyValueObservingOptionPrior.


The  +keyPathsForValuesAffectingKey mechanism relies on  
NSKeyValueObservingOptionPrior in order to do its magic.


Until such time as controller keys correctly support the KVO  
observing options, you can't


a) rely on Old/New/Prior in your own observers
	b) use a controller property as part of a key path in  
+keyPathsForValuesAffectingKey


- Jim



Thanks for pointing out why this is broken.
Presumably this has been radared to death.

Jonathan Mitchell

Central Conscious Unit
http://www.mugginsoft.com




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


How to clone a mutable dictionary

2009-04-24 Thread Steve Cronin

Folks;

Its been a long day and maybe I'm just in need of sleep but I'm  
bamboozeled...


I have an NSMutableDictionary (newThing) that is set up based on some  
user defaults and current contextual data.

newThing is fine.

What I want to do  is clone newThing (newThing2) and leave the values  
in newThing alone.

(I'll want to come and get newThing3 sooner or later)

Everything I do causes any change I make in newThing2 to also be made  
in newThing.


newThing2 = [NSMutableDictionary dictionaryWithCapacity:20];
[newThing2 setDictionary:newThing];
[newThing2 setObject:foo forKey:bar];  // at this method line  
[newThing objectForKey:bar] is now foo


I've tried [newThing copy) and enumerating over [newThing allKeys]  
doing a [newThing2 setObject:forKey]...

All with the same result

How do I make an independent clone of newThing1?   (XC3  / 10.5.6)

I'm sorry if this is something silly!
Steve
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How to clone a mutable dictionary

2009-04-24 Thread Graham Cox


On 24/04/2009, at 6:35 PM, Steve Cronin wrote:

Its been a long day and maybe I'm just in need of sleep but I'm  
bamboozeled...


I have an NSMutableDictionary (newThing) that is set up based on  
some user defaults and current contextual data.

newThing is fine.

What I want to do  is clone newThing (newThing2) and leave the  
values in newThing alone.

(I'll want to come and get newThing3 sooner or later)

Everything I do causes any change I make in newThing2 to also be  
made in newThing.


newThing2 = [NSMutableDictionary dictionaryWithCapacity:20];
[newThing2 setDictionary:newThing];
[newThing2 setObject:foo forKey:bar];  // at this method line  
[newThing objectForKey:bar] is now foo


I've tried [newThing copy) and enumerating over [newThing allKeys]  
doing a [newThing2 setObject:forKey]...

All with the same result

How do I make an independent clone of newThing1?   (XC3  / 10.5.6)

I'm sorry if this is something silly!



When a dictionary is copied, the objects it contains are not copied,  
merely retained by the second dictionary. Likewise setObject:forKey  
only retains the object.


You need to copy each object (deep copy) as it is transferred to the  
second dictionary.


i.e.id obj = [[newThing objectForKey:key] copy];
[newThing2 setObject:obj forKey:key];
[obj release];

--Graham


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How to clone a mutable dictionary

2009-04-24 Thread Jean-Daniel Dupas


Le 24 avr. 09 à 10:35, Steve Cronin a écrit :


Folks;

Its been a long day and maybe I'm just in need of sleep but I'm  
bamboozeled...


I have an NSMutableDictionary (newThing) that is set up based on  
some user defaults and current contextual data.

newThing is fine.

What I want to do  is clone newThing (newThing2) and leave the  
values in newThing alone.

(I'll want to come and get newThing3 sooner or later)

Everything I do causes any change I make in newThing2 to also be  
made in newThing.


newThing2 = [NSMutableDictionary dictionaryWithCapacity:20];
[newThing2 setDictionary:newThing];
[newThing2 setObject:foo forKey:bar];  // at this method line  
[newThing objectForKey:bar] is now foo


I've tried [newThing copy) and enumerating over [newThing allKeys]  
doing a [newThing2 setObject:forKey]...

All with the same result

How do I make an independent clone of newThing1?   (XC3  / 10.5.6)

I'm sorry if this is something silly!
Steve


NSMutableDictionary *newThing2 = [newThing mutableCopy];
[newThing2 setObject:foo forKey:bar];


But review you test, your first code sample should works too. How do  
you check the newThing changed too ?



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How to clone a mutable dictionary

2009-04-24 Thread Graham Cox


On 24/04/2009, at 6:39 PM, Graham Cox wrote:


I'm sorry if this is something silly!



When a dictionary is copied, the objects it contains are not copied,  
merely retained by the second dictionary. Likewise setObject:forKey  
only retains the object.


You need to copy each object (deep copy) as it is transferred to  
the second dictionary.


i.e.id obj = [[newThing objectForKey:key] copy];
[newThing2 setObject:obj forKey:key];
[obj release];



Incidentally this makes a very useful basic category on NSDictionary,  
one that every Cocoa programmer is likely to need sooner or later.  
Here's mine:


#import NSDictionary+DeepCopy.h

// setting this to 1 is not equivalent to a recursive deep copy if the  
items in the collection are also collections.


#define DO_IT_THE_EASY_WAY  0


@implementation NSDictionary (DeepCopy)


- (NSDictionary*)   deepCopy
{
#if DO_IT_THE_EASY_WAY
return [[NSDictionary alloc] initWithDictionary:self copyItems:YES];
#else   
NSMutableDictionary*copy;
NSEnumerator*   iter = [self keyEnumerator];
id  key, cobj;

copy = [[NSMutableDictionary alloc] init];

while(( key = [iter nextObject]))
{
cobj = [[self objectForKey:key] deepCopy];
[copy setObject:cobj forKey:key];
[cobj release];
}

return copy;
#endif
}


@end


Note that this implies that there exists a category for any object  
that implements -deepCopy (I have similar for NSObject, NSArray, etc)  
which thus ensures that the deep copy works no matter how deeply the  
structures are nested (i.e. dictionaries in dictionaries in  
dictionaries work). The use of initWithDiciotnary:copyItems: does NOT  
ensure this, though it would be OK if you knew for sure that your  
structure wasn't recursive.


I also use the same semantics for -deepCopy as for a normal -copy,  
that is, the object returned has a retain count of 1 and isn't  
autoreleased.


--Graham


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Best technology to use for overlays?

2009-04-24 Thread Daniel Vollmer

Hi,

I want to optimise my drawing code a bit. Essentially, I have a custom  
NSView embedded in an NSCollectionView embedded in an NSScrollView. In  
my custom view, I always want to display an overlay (consisting of  
something like a description string of what is being displayed). This  
overlay is of course expected to be always visible no matter where I  
scroll, which usually leads me to redrawing the whole view when  
scrolling.
What's the usual approach to this? Move the header drawing code to a  
subclass of NSScrollView? Conceptually, I think I want something that  
uses the same back-end as the window compositing, as that that's  
closest to what I want (the heading stays where it is, drawn on top of  
the NSScrollView, while the custom view only has to draw the given  
subRect that's being scrolled into the visible portion).


An example of the views is here: http://maven.de/code/wowplot/example_chains.png 
 . The description at the top-left of each plot always stays in the  
same position even when scrolling left or right.


Thanks for any suggestions,
Daniel.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How to clone a mutable dictionary

2009-04-24 Thread Jean-Daniel Dupas


Le 24 avr. 09 à 10:50, Graham Cox a écrit :



On 24/04/2009, at 6:44 PM, Jean-Daniel Dupas wrote:


NSMutableDictionary *newThing2 = [newThing mutableCopy];
[newThing2 setObject:foo forKey:bar];



This doesn't copy the contents of the dictionary, it only makes a  
mutable copy of the dictionary itself. If an object in the second  
dictionary is mutated, the same object in the first dictionary  
changes also. That is the OP's problem.


Of course, but that's not what this code is about:


newThing2 = [NSMutableDictionary dictionaryWithCapacity:20];
[newThing2 setDictionary:newThing];
[newThing2 setObject:foo forKey:bar];  // at this method line  
[newThing objectForKey:bar] is now foo


Here, the OP tells that the original dictionary (newThing) is updated  
when he set a value in the new dictionary (newThing2).




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Best technology to use for overlays?

2009-04-24 Thread Alexander Spohr

Did you try visibleRect?
Returns the portion of the receiver not clipped by its superviews.

- (NSRect)visibleRect



Make the header a subview of your datastream-view and put it into the  
visibleRect.


I hope the ScrollViews clipView does the needed job of clipping :)

atze


Am 24.04.2009 um 11:02 schrieb Daniel Vollmer:


Hi,

I want to optimise my drawing code a bit. Essentially, I have a  
custom NSView embedded in an NSCollectionView embedded in an  
NSScrollView. In my custom view, I always want to display an overlay  
(consisting of something like a description string of what is being  
displayed). This overlay is of course expected to be always visible  
no matter where I scroll, which usually leads me to redrawing the  
whole view when scrolling.
What's the usual approach to this? Move the header drawing code to  
a subclass of NSScrollView? Conceptually, I think I want something  
that uses the same back-end as the window compositing, as that  
that's closest to what I want (the heading stays where it is, drawn  
on top of the NSScrollView, while the custom view only has to draw  
the given subRect that's being scrolled into the visible portion).


An example of the views is here: http://maven.de/code/wowplot/example_chains.png 
 . The description at the top-left of each plot always stays in the  
same position even when scrolling left or right.


Thanks for any suggestions,
Daniel.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/atze%40freeport.de

This email sent to a...@freeport.de


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Best technology to use for overlays?

2009-04-24 Thread Michael Ash
On Fri, Apr 24, 2009 at 5:02 AM, Daniel Vollmer ma...@maven.de wrote:
 Hi,

 I want to optimise my drawing code a bit. Essentially, I have a custom
 NSView embedded in an NSCollectionView embedded in an NSScrollView. In my
 custom view, I always want to display an overlay (consisting of something
 like a description string of what is being displayed). This overlay is of
 course expected to be always visible no matter where I scroll, which usually
 leads me to redrawing the whole view when scrolling.
 What's the usual approach to this? Move the header drawing code to a
 subclass of NSScrollView? Conceptually, I think I want something that uses
 the same back-end as the window compositing, as that that's closest to what
 I want (the heading stays where it is, drawn on top of the NSScrollView,
 while the custom view only has to draw the given subRect that's being
 scrolled into the visible portion).

If you want to use the same back-end as window compositing, why not
use actual window compositing? Create a borderless NSWindow, make it a
child window, and position it appropriately.

Mike
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Best technology to use for overlays?

2009-04-24 Thread Chris Suter
Hi Daniel,

On Fri, Apr 24, 2009 at 9:07 PM, Michael Ash michael@gmail.com wrote:

 If you want to use the same back-end as window compositing, why not
 use actual window compositing? Create a borderless NSWindow, make it a
 child window, and position it appropriately.

In my opinion, you're better off having a view to display the overlays
if you can get it to work. I've had difficulties  getting child
windows to work well: problems with flickering when resizing windows
(due to the display of the windows not being automatically
synchronised) and there's also a small timing window where you can
place a child window in the wrong place (you have to position child
windows with absolute screen coordinates but the Window Server could
move the parent whilst you're doing that).

These problems aren't insurmountable although to solve the second
problem I had to use an undocumented API call. I had to use an overlay
window because I was overlaying an OpenGL window and it needed to work
pre Leopard.

One other minor point: child windows are hidden in the animation that
you get when you minimise the window although I haven't checked to see
if it's something I'm doing wrong; it's just something I noticed.

Regards,

Chris
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Best technology to use for overlays?

2009-04-24 Thread Michael Ash
On Fri, Apr 24, 2009 at 7:27 AM, Chris Suter csu...@sutes.co.uk wrote:
 Hi Daniel,

 On Fri, Apr 24, 2009 at 9:07 PM, Michael Ash michael@gmail.com wrote:

 If you want to use the same back-end as window compositing, why not
 use actual window compositing? Create a borderless NSWindow, make it a
 child window, and position it appropriately.

 In my opinion, you're better off having a view to display the overlays
 if you can get it to work. I've had difficulties  getting child
 windows to work well: problems with flickering when resizing windows
 (due to the display of the windows not being automatically
 synchronised) and there's also a small timing window where you can
 place a child window in the wrong place (you have to position child
 windows with absolute screen coordinates but the Window Server could
 move the parent whilst you're doing that).

 These problems aren't insurmountable although to solve the second
 problem I had to use an undocumented API call. I had to use an overlay
 window because I was overlaying an OpenGL window and it needed to work
 pre Leopard.

If your overlay is known about in advance, the solution to the timing
window is easy: load and position it immediately, when you load the
parent window, even if you don't need it yet. You can fill it with
nothing so that it's invisible, but this way there's no opportunity
for the positions to desynchronize.

Mike
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Best technology to use for overlays?

2009-04-24 Thread Chris Suter
Hi Michael,

On Fri, Apr 24, 2009 at 9:38 PM, Michael Ash michael@gmail.com wrote:

 If your overlay is known about in advance, the solution to the timing
 window is easy: load and position it immediately, when you load the
 parent window, even if you don't need it yet. You can fill it with
 nothing so that it's invisible, but this way there's no opportunity
 for the positions to desynchronize.

Unfortunately, that approach won't work, or rather, it works until you
have to resize it. There's no setFrameSize method, only a setFrame
method so when you have to resize your overlay window, you have to set
the position at the same time.

And that, of course, is another hassle with child windows: it's more
tricky when it comes to resizing them.

Regards,

Chris
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Best technology to use for overlays?

2009-04-24 Thread Chris Suter
Hi Michael,

And I've just thought of more things that are awkward with child
windows: handling events and accessibility.

Regards,

Chris
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Dividing NSView to subviews

2009-04-24 Thread Naresh Kongara

Thanks peter for your reply,

Now there is some improvement in the performance , but the image is  
not that much clear as the image we are getting with  
dataWithPDFInsideRect:


is there any way to remove that blur.


Thanks,
nareshk


On Apr 24, 2009, at 10:40 AM, Peter N Lewis wrote:



On 23/04/2009, at 14:11 , Naresh Kongara wrote:


I have a NSView which i want to divide into to required sub views.

I implemented it using NSView's dataWithPDFInsideRect: 
(NSRect )aRect,   i.e  constructed a image view with the data i got .

This process is taking long time if the view is large one..

Is there any other way to get the required part of a View.



Ironically (or perhaps fortuitously) I've been dealing with this  
issue reasonly and just posted a result of my research and  
experiments at


http://www.stairways.com/blog/2009-04-21-nsimage-from-nsview

The end result was a category on NSView:

- (NSImage *)imageWithSubviews
{
NSSize mySize = self.bounds.size;
NSSize imgSize = NSMakeSize( mySize.width, mySize.height );

	NSBitmapImageRep *bir = [self bitmapImageRepForCachingDisplayInRect: 
[self bounds]];

[bir setSize:imgSize];
[self cacheDisplayInRect:[self bounds] toBitmapImageRep:bir];

NSImage* image = [[[NSImage alloc]initWithSize:imgSize] autorelease];
[image addRepresentation:bir];
return image;
}
Based on Greg Knobs post http://www.cocoabuilder.com/archive/message/cocoa/2007/11/17/193329 
.

Enjoy,
  Peter.

--
Run macros from your iPhone with Keyboard Maestro Control!
or take a break with Derzle for your iPhone

Keyboard Maestro http://www.keyboardmaestro.com/ Macros for your Mac
Aragom Space War http://www.stairways.com/iphone/aragom Don't get  
killed!
Derzle http://www.stairways.com/iphone/derzle Enjoy a relaxing  
puzzle.

http://www.stairways.com/   http://download.stairways.com/




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/naresh.kongara%40prithvisolutions.com

This email sent to naresh.kong...@prithvisolutions.com







___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


RE: How to clone a mutable dictionary

2009-04-24 Thread Kirk Kerekes
Simple, brute-force method: archive the dictionary, then unarchive it.  
The result is a 1-line deep copy.


Of course, that assumes that all the dictionary objects/keys support  
archiving.



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Best technology to use for overlays?

2009-04-24 Thread Daniel Vollmer


On Apr 24, 2009, at 11:06 , Frederik Slijkerman wrote:


Hi Daniel,

Why not move the overlay drawing to a separate custom view, that you  
insert as a direct subview of the scroll view? In this way, the  
composition system takes care of all the redrawing in the most  
efficient way.


The thing that makes this difficult is that I need to draw the heading  
for each of the subviews of the NSCollectionView, and thus the layout  
and current y-position of where to draw the headers is not really  
known in superviews of the collection view (although I could probably  
ask them =)).
Also, somewhere in the back of my mind was the mention of a  
restriction that subviews were not allowed to overlap, but I may be  
wrong on that account.



Best regards,
Frederik Slijkerman.


Daniel.


Daniel Vollmer wrote:

Hi,
I want to optimise my drawing code a bit. Essentially, I have a  
custom NSView embedded in an NSCollectionView embedded in an  
NSScrollView. In my custom view, I always want to display an  
overlay (consisting of something like a description string of what  
is being displayed). This overlay is of course expected to be  
always visible no matter where I scroll, which usually leads me to  
redrawing the whole view when scrolling.
What's the usual approach to this? Move the header drawing code  
to a subclass of NSScrollView? Conceptually, I think I want  
something that uses the same back-end as the window compositing, as  
that that's closest to what I want (the heading stays where it is,  
drawn on top of the NSScrollView, while the custom view only has to  
draw the given subRect that's being scrolled into the visible  
portion).
An example of the views is here: http://maven.de/code/wowplot/example_chains.png 
 . The description at the top-left of each plot always stays in the  
same position even when scrolling left or right.

Thanks for any suggestions,
   Daniel.
___
Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/fjs%40xs4all.nl
This email sent to f...@xs4all.nl




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Detecting changes to NSPopUpButtonCell in an NSTableView

2009-04-24 Thread Jerry Krinock


On 2009 Apr 23, at 16:39, Ulai Beekam wrote:

Furthermore, it doesn't seem to make too much sense  to bind the  
selected index to a single variable because, as you say, I have  
multiple rows and the popupmenu for each one.


Actually I can think of one weird way of making it work: Having an  
instance variable int selectedIndex with ONLY a setter method (NOT  
a getter method). That way change in one of the rows will not  
propagate to other rows. And I can then do my stuff in the setter  
method. But hmm, this is just too weird to be the best solution  
available out there, assuming it even works :S


Indeed, this is too weird.  The normal way to use bindings with a  
table is to bind through an array controller to the key path  
arrangedObjects.foo.  Almost any Apple Sample Project containing a  
table will do this.


However, this is only relevant if you want to convert your table to  
use bindings.


Getting back to your original question, without using bindings, I'd  
say that you detect changes in the implementation of the action method  
which you have assigned to the NSPopUpButtonCell's menu.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How to clone a mutable dictionary

2009-04-24 Thread Graham Cox


On 24/04/2009, at 6:44 PM, Jean-Daniel Dupas wrote:


NSMutableDictionary *newThing2 = [newThing mutableCopy];
[newThing2 setObject:foo forKey:bar];



This doesn't copy the contents of the dictionary, it only makes a  
mutable copy of the dictionary itself. If an object in the second  
dictionary is mutated, the same object in the first dictionary changes  
also. That is the OP's problem.


--Graham


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Best technology to use for overlays?

2009-04-24 Thread Mike Abdullah
Just position your overlay view as a sibling to the scrollview. If  
you're using NSCollectionView, you're targeting Leopard+, where  
overlapping views are properly supported.


On 24 Apr 2009, at 10:02, Daniel Vollmer wrote:


Hi,

I want to optimise my drawing code a bit. Essentially, I have a  
custom NSView embedded in an NSCollectionView embedded in an  
NSScrollView. In my custom view, I always want to display an overlay  
(consisting of something like a description string of what is being  
displayed). This overlay is of course expected to be always visible  
no matter where I scroll, which usually leads me to redrawing the  
whole view when scrolling.
What's the usual approach to this? Move the header drawing code to  
a subclass of NSScrollView? Conceptually, I think I want something  
that uses the same back-end as the window compositing, as that  
that's closest to what I want (the heading stays where it is, drawn  
on top of the NSScrollView, while the custom view only has to draw  
the given subRect that's being scrolled into the visible portion).


An example of the views is here: http://maven.de/code/wowplot/example_chains.png 
 . The description at the top-left of each plot always stays in the  
same position even when scrolling left or right.


Thanks for any suggestions,
Daniel.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/cocoadev%40mikeabdullah.net

This email sent to cocoa...@mikeabdullah.net


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How to clone a mutable dictionary

2009-04-24 Thread Chris Suter
Hi Graham,

On Fri, Apr 24, 2009 at 6:49 PM, Graham Cox graham@bigpond.com wrote:

 Incidentally this makes a very useful basic category on NSDictionary, one
 that every Cocoa programmer is likely to need sooner or later. Here's
mine:
[snip]

You could also use CFPropertyListCreateDeepCopy. Just remember to call
NSMakeCollectable on the result if you're using garbage collection.
Regards,

Chris
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


NSPopUpButtonCell causes UI to sleep when clicked

2009-04-24 Thread Jerry Krinock

I'm creating an NSPopUpButtonCell programatically.

To show the menu I invoke -[NSPopUpButtonCell  
performClickWithFrame:inView:].  It works -- however after the menu  
has popped up, been clicked and dismissed,


  - Timers in the main thread stop firing
  - Keyboard equivalents fail silently

Operation does not return to normal until the user clicks another  
control TWICE.  It seems to me that the UI is sleeping and that the  
first click is necessary to wake it.


Is there a name for this state when the UI is sleeping?  Maybe if I  
knew that I could research how to fix it.  Of course, a fix would be  
appreciated too :)


I guessed that the popup menu may still be tracking the mouse  
(although I don't really know what that means).  However, invoking - 
cancelTracking does not help.


Also, invoking -attachPopUpWithFrame:inView: before  
performClickWithFrame:: does not help either.  (I've never been able  
to find an explanation of what -attachPopUpWithFrame:inView: is  
supposed to do.  As far as I can see it's a no-op.)


Jerry Krinock



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSTableView variable row height and noteHeightOfRowsWithIndexesChanged during live resize

2009-04-24 Thread Corbin Dunn


On Apr 23, 2009, at 5:44 PM, Stuart Malin wrote:



On Apr 23, 2009, at 1:18 PM, Corbin Dunn wrote:



On Apr 23, 2009, at 3:37 PM, Stuart Malin wrote:



On Apr 23, 2009, at 12:33 PM, Corbin Dunn wrote:



On Apr 23, 2009, at 2:55 PM, Stuart Malin wrote:

I have an NSTableView with a single column that has a custom  
cell. During a live resize, I recalculate the row height in the  
delegate method -tableView:heightForRow: and return the result.  
However, some rows don't grow larger. I presume I need to call  
the tableview's -noteHeightOfRowsWithIndexesChanged for each row  
that has a height change. Is it okay to call this from within  
the tableView:heightForRow: method?


No, it is not; you'll have to redo your logic, or call it with a  
range for all rows (probably the easiest thing to do).



Thanks Corbin.

What about from within the tableview delegate method - 
tableViewColumnDidResize  ?


That is fine; note that it is only sent out when the live-resize  
method ends. Your calculation in -heightForRow: can't depend on the  
-[tableColumn width], unless you call the -noteHeightXX method more  
frequently (ie: you'd have to capture when the setWidth: happens by  
subclassing the table column).



I subclassed the table column and overrode its -setWidth method.  
When that is invoked, I recalculate the cell heights for *only* the  
visible rows. I keep track of those rows that change, prepare an  
index set, and notify the table view with -noteHeightXXX.


Works like a charm!

Question: presently, in the overridden -setWidth, I invoke - 
noteHeightXXX *before* calling [super setWidth:newWidth]As I  
said, this works, and seems to me to be the logical ordering of  
events, but just want to check if I should be calling -noteHeightXXX  
*after* invoking the super (NSTableColumn) -setWidth.




That should be okay since layout is done lazily (in -viewWillDraw:),  
but you may want to call the note after calling [super setWidth:]. The  
reasoning is as follows: if the -noteHeightXX method calls your  
delegate immediately, and it then recalculates a new row height based  
on the [column width], then things will be wrong. In practice, this  
doesn't happen, but there is no reason it couldn't.


corbin


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How to clone a mutable dictionary

2009-04-24 Thread Steve Cronin

Graham;

THANK-YOU for this informative and full-bodied answer!

I want make sure I fully understand:

1) The Easy Way  works only if there are no collection objects as  
values in the copied dictionary (or other collection).
It seems to me that the Hard Way is ultimately necessary for every  
Cocoa programmer.

Given that,  I am inclined to just implement the Hard Way and be done.
It just seems too much bother to try and figure out if any random  
future item is qualified for the Easy Way.  (code obfuscation- to  
what end?)

Is there a compelling counter-argument against this viewpoint?

2) By establishing a category on NSObject, one goal you accomplish is  
making -deepCopy available to custom objects that are sub-classed  
directly from NSObject. True?  Are there other reasons why one would  
want to implement for NSObject?  Since there is nothing to iterate  
over in NSObject is this a correct implementation for NSObject:


@implementation NSDictionary (DeepCopy)
- (NSObject *)	deepCopy { return [[[self class] allocWithZone:[self  
zone]] init]; }

@end

3) If -deepCopy is implemented as above on NSObject then when you  
implement a -deepCopy on a collection it overrides the NSObject  
version and all is well.  Nothing special need be done (ie no need for  
a separately named -deepArrayCopy).


4) The suite of collections include: array, dictionary, and set.  (I'm  
an NSSet fan!)  The mutable flavors all inherit from these 3 base  
types and the countedSet inherits from mutableSet.  So implementing  
the -deepCopy on NSObject, NSArray, NSDictionary, and NSSet should  
provide a comprehensive solution .  Do you agree?


5) Your allusion to semantics is calling attention to the fact that  
the returned object is to be treated in the same way as any system- 
vended object from a -copy or -alloc-int.  The requestor has the  
responsibility for releasing the returned object.


6) The code you show for the Hard Way returns a mutableDictionary  
where the signature promises a NSDictionary.  The mutable flavor is  
useful for the construction during  iteration but is there a reason  
for returning something other than what was promised?


Again really good stuff!  Thanks!
Steve

On Apr 24, 2009, at 3:49 AM, Graham Cox wrote:



On 24/04/2009, at 6:39 PM, Graham Cox wrote:


I'm sorry if this is something silly!



When a dictionary is copied, the objects it contains are not  
copied, merely retained by the second dictionary. Likewise  
setObject:forKey only retains the object.


You need to copy each object (deep copy) as it is transferred to  
the second dictionary.


i.e.id obj = [[newThing objectForKey:key] copy];
[newThing2 setObject:obj forKey:key];
[obj release];



Incidentally this makes a very useful basic category on  
NSDictionary, one that every Cocoa programmer is likely to need  
sooner or later. Here's mine:


#import NSDictionary+DeepCopy.h

// setting this to 1 is not equivalent to a recursive deep copy if  
the items in the collection are also collections.


#define DO_IT_THE_EASY_WAY  0


@implementation NSDictionary (DeepCopy)


- (NSDictionary*)   deepCopy
{
#if DO_IT_THE_EASY_WAY
return [[NSDictionary alloc] initWithDictionary:self copyItems:YES];
#else   
NSMutableDictionary*copy;
NSEnumerator*   iter = [self keyEnumerator];
id  key, cobj;

copy = [[NSMutableDictionary alloc] init];

while(( key = [iter nextObject]))
{
cobj = [[self objectForKey:key] deepCopy];
[copy setObject:cobj forKey:key];
[cobj release];
}

return copy;
#endif
}


@end


Note that this implies that there exists a category for any object  
that implements -deepCopy (I have similar for NSObject, NSArray,  
etc) which thus ensures that the deep copy works no matter how  
deeply the structures are nested (i.e. dictionaries in dictionaries  
in dictionaries work). The use of initWithDiciotnary:copyItems: does  
NOT ensure this, though it would be OK if you knew for sure that  
your structure wasn't recursive.


I also use the same semantics for -deepCopy as for a normal -copy,  
that is, the object returned has a retain count of 1 and isn't  
autoreleased.


--Graham




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


NSPopUpButton with multiple selection state (like NSMixedState)

2009-04-24 Thread ALEXander

Hello,

I am looking for a possibility to display a NSMixedState for an  
NSPopUpButton (like it is used OmniGraffle):




I have some objects. Each object can be in one and only one group.  
There are multiple groups and objects. I want to assign the group to  
the objects via an NSPopUpButton.


Now when I select multiple objects from different groups, I want the  
NSPopUpButton to display a title like Multiple selection. If the  
user then clicks on it, he or she can choose a new group for all the  
objects in the selection.




I did some websearching, but did not find anything. Any ideas? I would  
now try to subclass NSPopUpButton and implement an NSMixedState like  
there is for NSButton. But I am sure the subclass must be out there  
somewhere... (are you reading this OmniGroup? :)


Thanks, ALEXander.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How to clone a mutable dictionary

2009-04-24 Thread Mike Abdullah


On 24 Apr 2009, at 17:15, Steve Cronin wrote:


Graham;

THANK-YOU for this informative and full-bodied answer!

I want make sure I fully understand:

1) The Easy Way  works only if there are no collection objects as  
values in the copied dictionary (or other collection).
It seems to me that the Hard Way is ultimately necessary for  
every Cocoa programmer.
Given that,  I am inclined to just implement the Hard Way and be  
done.
It just seems too much bother to try and figure out if any random  
future item is qualified for the Easy Way.  (code obfuscation- to  
what end?)

Is there a compelling counter-argument against this viewpoint?


They hard way only offers a benefit over the easy way if you've got a  
structure stacking 3 or more mutable objects inside each other. e.g.  
the easy way on this would not copy that final mutable dictionary:


NSMutableArray
NSMutableSet
NSMutableDictionary

BUT, such an amount of stacking often suggests a poor model design.  
Consider whether there should be some custom classes in there to  
handle it better.





2) By establishing a category on NSObject, one goal you accomplish  
is making -deepCopy available to custom objects that are sub-classed  
directly from NSObject. True?  Are there other reasons why one would  
want to implement for NSObject?  Since there is nothing to iterate  
over in NSObject is this a correct implementation for NSObject:


@implementation NSDictionary (DeepCopy)
- (NSObject *)	deepCopy { return [[[self class] allocWithZone:[self  
zone]] init]; }

@end


Assuming you changed NSDictionary to NSObject, then no. instead  
you want:


return [self copy]

which will create a copy if the object supports it, or raise an  
exception if it doesn't.



3) If -deepCopy is implemented as above on NSObject then when you  
implement a -deepCopy on a collection it overrides the NSObject  
version and all is well.  Nothing special need be done (ie no need  
for a separately named -deepArrayCopy).


4) The suite of collections include: array, dictionary, and set.   
(I'm an NSSet fan!)  The mutable flavors all inherit from these 3  
base types and the countedSet inherits from mutableSet.  So  
implementing the -deepCopy on NSObject, NSArray, NSDictionary, and  
NSSet should provide a comprehensive solution .  Do you agree?


5) Your allusion to semantics is calling attention to the fact that  
the returned object is to be treated in the same way as any system- 
vended object from a -copy or -alloc-int.  The requestor has the  
responsibility for releasing the returned object.


6) The code you show for the Hard Way returns a mutableDictionary  
where the signature promises a NSDictionary.  The mutable flavor is  
useful for the construction during  iteration but is there a reason  
for returning something other than what was promised?


The code does return what was promised: An object that is an  
NSDictionary or subclass
It would only be a breach of contract if that dictionary were to be  
somehow mutated by the category method at a later time, which is  
clearly not going to happen. Returning the mutable object saves memory  
usage compared to creating an immutable object. Of course this might  
not be in your favour in some particularly intensive task, so you  
could tweak it later if desired.


HOWEVER, there's a reason why Cocoa has both -copy and -mutableCopy.  
You might find that you actually want -deepCopy AND -deepMutableCopy.


Mike.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSPopUpButton with multiple selection state (like NSMixedState)

2009-04-24 Thread Jerry Krinock


On 2009 Apr 24, at 08:43, ALEXander wrote:

I am looking for a possibility to display a NSMixedState for an  
NSPopUpButton (like it is used OmniGraffle):







If you pasted an image in there, it did not make it through the email  
server.  (Interesting, because I have seen small images make it  
through in the past.)


Anyhow, I believe you want a popup menu which shows a constant title  
instead of showing the selected item.  Such a control is actually a  
popup menu which has been set to pull down


http://developer.apple.com/documentation/Cocoa/Conceptual/MenuList/Articles/HowMenusWork.html

Read the section Pop-Up Buttons and Pull-Down Lists.

Send -setPullsDown: to make a popp button have the pulldown behavior.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSPopUpButton with multiple selection state (like NSMixedState)

2009-04-24 Thread ALEXander
If you pasted an image in there, it did not make it through the  
email server.  (Interesting, because I have seen small images make  
it through in the past.)


No, that was just a big white space to keep text and context apart :)

Anyhow, I believe you want a popup menu which shows a constant  
title instead of showing the selected item.  Such a control is  
actually a popup menu which has been set to pull down


No, because the control will just be a normal popup for selecting a  
group if only one object is selected. It is never possible to actually  
select multiple groups. But the case can happen that the user selectes  
multiple objects with different groups. It like a three-state  
checkbox, essentially.


Best, ALEXander.



On 24.04.2009, at 17:34, Jerry Krinock wrote:



On 2009 Apr 24, at 08:43, ALEXander wrote:

I am looking for a possibility to display a NSMixedState for an  
NSPopUpButton (like it is used OmniGraffle):







If you pasted an image in there, it did not make it through the  
email server.  (Interesting, because I have seen small images make  
it through in the past.)


Anyhow, I believe you want a popup menu which shows a constant  
title instead of showing the selected item.  Such a control is  
actually a popup menu which has been set to pull down


http://developer.apple.com/documentation/Cocoa/Conceptual/MenuList/Articles/HowMenusWork.html

Read the section Pop-Up Buttons and Pull-Down Lists.

Send -setPullsDown: to make a popp button have the pulldown behavior.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/alexander%40wackazong.com

This email sent to alexan...@wackazong.com


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How to clone a mutable dictionary

2009-04-24 Thread Steve Cronin

Mike;

Thank-you also.  The goodness' just doesn't stop... ;-)

My bad on the NSObject code - thanks for clarifying...
(How on earth could init yield a copy?)

But at the end of your message you say ...there's a reason why Cocoa  
has both -copy and -mutableCopy. ..


Is the reason you are alluding to the complications due to instance  
variables that is noted in the NSMutableCopying Protocol notes?

Or are you thinking of another reason?

Steve

On Apr 24, 2009, at 11:34 AM, Mike Abdullah wrote:



On 24 Apr 2009, at 17:15, Steve Cronin wrote:


Graham;

THANK-YOU for this informative and full-bodied answer!

I want make sure I fully understand:

1) The Easy Way  works only if there are no collection objects as  
values in the copied dictionary (or other collection).
It seems to me that the Hard Way is ultimately necessary for  
every Cocoa programmer.
Given that,  I am inclined to just implement the Hard Way and be  
done.
It just seems too much bother to try and figure out if any random  
future item is qualified for the Easy Way.  (code obfuscation- to  
what end?)

Is there a compelling counter-argument against this viewpoint?


They hard way only offers a benefit over the easy way if you've got  
a structure stacking 3 or more mutable objects inside each other.  
e.g. the easy way on this would not copy that final mutable  
dictionary:


NSMutableArray
   NSMutableSet
   NSMutableDictionary

BUT, such an amount of stacking often suggests a poor model design.  
Consider whether there should be some custom classes in there to  
handle it better.





2) By establishing a category on NSObject, one goal you accomplish  
is making -deepCopy available to custom objects that are sub- 
classed directly from NSObject. True?  Are there other reasons why  
one would want to implement for NSObject?  Since there is nothing  
to iterate over in NSObject is this a correct implementation for  
NSObject:


@implementation NSDictionary (DeepCopy)
- (NSObject *)	deepCopy { return [[[self class] allocWithZone:[self  
zone]] init]; }

@end


Assuming you changed NSDictionary to NSObject, then no. instead  
you want:


return [self copy]

which will create a copy if the object supports it, or raise an  
exception if it doesn't.



3) If -deepCopy is implemented as above on NSObject then when you  
implement a -deepCopy on a collection it overrides the NSObject  
version and all is well.  Nothing special need be done (ie no need  
for a separately named -deepArrayCopy).


4) The suite of collections include: array, dictionary, and set.   
(I'm an NSSet fan!)  The mutable flavors all inherit from these 3  
base types and the countedSet inherits from mutableSet.  So  
implementing the -deepCopy on NSObject, NSArray, NSDictionary, and  
NSSet should provide a comprehensive solution .  Do you agree?


5) Your allusion to semantics is calling attention to the fact that  
the returned object is to be treated in the same way as any system- 
vended object from a -copy or -alloc-int.  The requestor has the  
responsibility for releasing the returned object.


6) The code you show for the Hard Way returns a mutableDictionary  
where the signature promises a NSDictionary.  The mutable flavor is  
useful for the construction during  iteration but is there a reason  
for returning something other than what was promised?


The code does return what was promised: An object that is an  
NSDictionary or subclass
It would only be a breach of contract if that dictionary were to be  
somehow mutated by the category method at a later time, which is  
clearly not going to happen. Returning the mutable object saves  
memory usage compared to creating an immutable object. Of course  
this might not be in your favour in some particularly intensive  
task, so you could tweak it later if desired.


HOWEVER, there's a reason why Cocoa has both -copy and -mutableCopy.  
You might find that you actually want -deepCopy AND -deepMutableCopy.


Mike.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


WebView setDownloadDelegate: issue

2009-04-24 Thread Mikkel Eriksen
Hi foks

Hopefully the right place to ask this question.

In the project I'm working on, I have a webview that's going to a
specific site. When the user downloads files from that site, I want to
intercept them (basically grab the URL, get the file and parse the
contents).

So in my controller class I have

IBOutlet WebView *webview; //in controller.h
//and
[webview setDownloadDelegate:self]; //in the controller awakeFromNib

//I also took this from Hillegass' book to get a feel for how
downloads work (what delegate methods are called and when):
- (BOOL)respondsToSelector:(SEL)aSelector
{
   NSString *methodName = NSStringFromSelector(aSelector);
   NSLog(@respondsToSelector: %@, methodName);
   return [super respondsToSelector:aSelector];
}

Now that works with a sampling of random sites I went to:

2009-04-23 22:01:41.122 AO[42395:10b] respondsToSelector: downloadDidBegin:
2009-04-23 22:01:41.124 AO[42395:10b] respondsToSelector:
download:willSendRequest:redirectResponse:
2009-04-23 22:01:41.458 AO[42395:10b] respondsToSelector:
download:didReceiveResponse:
2009-04-23 22:01:41.460 AO[42395:10b] respondsToSelector:
download:didReceiveDataOfLength:
2009-04-23 22:01:41.569 AO[42395:10b] respondsToSelector:
download:didReceiveDataOfLength:
2009-04-23 22:01:41.983 AO[42395:10b] respondsToSelector:
download:decideDestinationWithSuggestedFilename:
2009-04-23 22:01:41.985 AO[42395:10b] respondsToSelector:
download:didCreateDestination:
etc


But with the specific links on that site, it did not work. No delegate
methods were called.

The problem as far as I can guess is that the links are actually
javascripts that fill out values in a form and submits it to the
server, which then spits out the file. Is there a clean way to
intercept these files?

Regards,
Mikkel
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Clicking through a NSView with CALayers

2009-04-24 Thread Rowan Nairn
Hi,

I have a transparent overlay NSWindow the size if the screen and it
contains a mostly transparent NSView.  I'd like to accept clicks which
occur on non-transparent regions of the view but let clicks that occur
over transparent regions activate the app underneath.  If I draw the
view using drawRect: then this works well.

However I'd also like to use Core Animation in my view.  If I
setWantsLayer:YES and draw using CALayers then clicks over transparent
regions no longer get passed to apps underneath my window.

Is it possible to have my cake and eat it too?

Rowan
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How to clone a mutable dictionary

2009-04-24 Thread Jerry Krinock
I spent some time on this problem a couple months ago and found some  
code on cocoadev which I improved upon, also added a little test  
code.  There still may be bugs in it.


I don't know what the byte/character limit is on this list, but at  
least the header should make it through.


-

#import Cocoa/Cocoa.h

/*!
 @briefCategories for making mutable deep copies of dictionaries,
 arrays and sets.

 @details   The original author says that this doesn't work:
 ... for the life of me I can't figure out why, it seems that -copy
 is always a copy of the pointers. Examining two dictionaries in the
 debugger using this method shows that the objects have different
 pointers but their components are identical, STILL. So it seems not
 to work.

 Note that another way to make a deep copy is
 make an archive of it and immediately unarchive it into a
 different variable. The only down-side is that the object to
 be copied must implement NSCoding.

 To do that,
 id foo = ... ;
 NSData* fooArchive = [NSKeyedArchiver  
archivedDataWithRootObject:foo] ;

 id fooCopy = [NSKeyedUnarchiver unarchiveObjectWithData:fooArchive] ;

 Source: http://www.cocoadev.com/index.pl? 
MutableDeepCopyAndUserDefaults

 */

/*!
 @briefA category of NSObject which produces deep copies
 of collections containing dictionaries, arrays and/or sets.

 @details
 */


/*!
 @briefRule for how to clone leaf nodes when making a deep copy.

 @details  These are listed in order from least stringent
 to most stringent.
*/
typedef NSInteger SSYCloneStyleBitmask ;

extern SSYCloneStyleBitmask const SSYCloneStyleBitmaskCopy ;
extern SSYCloneStyleBitmask const SSYCloneStyleBitmaskMutable ;
extern SSYCloneStyleBitmask const SSYCloneStyleBitmaskEncodeable ;
extern SSYCloneStyleBitmask const SSYCloneStyleBitmaskSerializable ;

@interface NSObject (DeepCloning)

/*!
 @briefReturns a deep, mutable copy of the receiver

 @details  If an object responds to -mutableCopyWithZone and
 -count, it is treated as a container node.nbsp;

 Leaf nodes are treated as follows:
 ul
 liIf the style mask specifies serializable but an object is not
 serializable, its image in the returned result will be its
 -description./li
 liElse, if the style mask specifies encodeable but an object is not
 encodeable with NSKeyedArchiver, its image in the returned result
 will be its -description./li
 liElse, if the style mask specifies mutable and the object responds
 to -mutableCopyWithZone:, its image in the returned result will be a
 mutable copy of the object./li
 liElse, if the style mask specifies copy and the object responds to
 -copyWithZone:, its image the returned result will be a copy
 of the object./li
 liElse, its image in the returned result is the object itself./li
 /ul

 @paramstyle  Determines the makeup of non-collection
 objects in the result */
- mutableDeepCloneStyle:(SSYCloneStyleBitmask)style;

@end

#import NSObject+DeepCloning.h

SSYCloneStyleBitmask const SSYCloneStyleBitmaskCopy = 1 ;
SSYCloneStyleBitmask const SSYCloneStyleBitmaskMutable = 2 ;
SSYCloneStyleBitmask const SSYCloneStyleBitmaskEncodeable = 4 ;
SSYCloneStyleBitmask const SSYCloneStyleBitmaskSerializable = 8 ;

@implementation NSObject (DeepCloning)

- copyLeafStyle:(SSYCloneStyleBitmask)style {
if(
   ((style  SSYCloneStyleBitmaskSerializable) != 0)
   
   ![NSPropertyListSerializationdataFromPropertyList:self

format:NSPropertyListBinaryFormat_v1_0

 errorDescription:NULL]
   ) {
// Invoker specified serializable but self is not serializable.
// Return a description
return [[self description] retain] ;
}
else if(
((style  SSYCloneStyleBitmaskMutable) != 0)

![NSKeyedArchiver archivedDataWithRootObject:self]
) {
// Invoker specified mutable and self is mutable
// Return a mutable copy
return [[self description] retain] ;
}
else if(
((style  SSYCloneStyleBitmaskCopy) != 0)

[self respondsToSelector:@selector(copyWithZone:)]
) {
// Invoker specified copy and self is copyable
// Return a copy
return [self copy];
}
else {
// Return self
return [self retain];
}
}

- mutableDeepCloneStyle:(SSYCloneStyleBitmask)style {
if (
[self respondsToSelector:@selector(mutableCopyWithZone:)]

[self respondsToSelector:@selector(count)]) {
return [self mutableCopy] ;
}
else {
return [self copyLeafStyle:style] ;
}

// Supress compiler warning
return nil ;
}

@end

@implementation NSDictionary (DeepCloning)

- mutableDeepCloneStyle:(SSYCloneStyleBitmask)style {
NSMutableDictionary *newDictionary = [[NSMutableDictionary alloc]  
init];

for (id key in self) {
id obj = [[self objectForKey:key] 

Re: WebView setDownloadDelegate: issue

2009-04-24 Thread Jeff Johnson

Hi Mikkel.

The Webkitsdk-dev list would probably be better for this question.

Having said that, does your webview also have a UIDelegate? I ask  
because many downloads try to open a new window, so I'm wondering if  
webView:createWebViewWithRequest: would be called, for example. If you  
don't implement that delegate method, I believe that it just doesn't  
create a new webview, which would explain why the download fails.


-Jeff


On Apr 24, 2009, at 5:29 AM, Mikkel Eriksen wrote:


Hi foks

Hopefully the right place to ask this question.

In the project I'm working on, I have a webview that's going to a
specific site. When the user downloads files from that site, I want to
intercept them (basically grab the URL, get the file and parse the
contents).

So in my controller class I have

IBOutlet WebView *webview; //in controller.h
//and
[webview setDownloadDelegate:self]; //in the controller awakeFromNib

//I also took this from Hillegass' book to get a feel for how
downloads work (what delegate methods are called and when):
- (BOOL)respondsToSelector:(SEL)aSelector
{
  NSString *methodName = NSStringFromSelector(aSelector);
  NSLog(@respondsToSelector: %@, methodName);
  return [super respondsToSelector:aSelector];
}

Now that works with a sampling of random sites I went to:

2009-04-23 22:01:41.122 AO[42395:10b] respondsToSelector:  
downloadDidBegin:

2009-04-23 22:01:41.124 AO[42395:10b] respondsToSelector:
download:willSendRequest:redirectResponse:
2009-04-23 22:01:41.458 AO[42395:10b] respondsToSelector:
download:didReceiveResponse:
2009-04-23 22:01:41.460 AO[42395:10b] respondsToSelector:
download:didReceiveDataOfLength:
2009-04-23 22:01:41.569 AO[42395:10b] respondsToSelector:
download:didReceiveDataOfLength:
2009-04-23 22:01:41.983 AO[42395:10b] respondsToSelector:
download:decideDestinationWithSuggestedFilename:
2009-04-23 22:01:41.985 AO[42395:10b] respondsToSelector:
download:didCreateDestination:
etc


But with the specific links on that site, it did not work. No delegate
methods were called.

The problem as far as I can guess is that the links are actually
javascripts that fill out values in a form and submits it to the
server, which then spits out the file. Is there a clean way to
intercept these files?

Regards,
Mikkel

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


CoreData delete clean up

2009-04-24 Thread Jim Thomason
I just can't find a solution for this. Basically, I need a pre-delete
hook in CoreData but can't seem to find one.

Here's the deal - I have a Foo object which has many Bar objects. Foo
also has a property that's calculated off of the various values in
Bar.

So Bar has many custom setKey methods that twiddle the value up in
the Foo object to keep it up to date. All works well and good.

The problem is if I delete a Bar object. I need a way to have the Bar
object revert the cached Foo property to what it would've been had it
never existed. Basically, a pre-delete cleanup hook.

So what happens is, upon delete it marches through all of my setKey
methods in some order to wipe them out and screws up my cached
property. Basically, it ends up backing out the Bar object multiple
times, since while it's knocking out all of the properties, it doesn't
know that the object is actually deleted. Boom. Big mess.

Problems and caveats:
* I can't just have Foo monitor removeBarObject because it's not
guaranteed to wipe out the relationship first. It may have called a
half a dozen custom setKeys in Bar first so I'm still in some
inconsistent state.
* I have to have Bar notify Foo of changes (as opposed to having Foo
observe all of Bar's related properties) since there are relatively
few Foo objects and a -lot- of Bars. Further, the Bars only rarely
change their value. So to have a few Foos monitoring tons of Bars all
the time is just going to create a whole bunch of additional overhead
that I don't want.
* I have to store the property up in Foo, since it can also be
manipulated via other means. That is, I can't just replace the
calculated property with keyPath monitoring of the Bars.
* validateForDelete is called way too late in the process. I watched
it. It's very helpfully called after my object data is wiped out, all
of my setKeys are called, and my object's a mess.
* likewise for isDeleted. Doesn't work as a flag.

Possibilities:
* I can add an explicit flagForDeletion method to my Bar object and
explicitly call this every time I'm going to delete one. This seems
error-prone to me, since I may forget to put it somewhere. Further, it
makes it difficult to use in abstract situations unless I add dummy
flagForDeletion flags to all of my objects just to ensure that I can
always call the method. I know I can do it with a category, but still.
Likewise, I can add that into my ArrayController to handle the
majority of the cases.

For now, I've gone with that approach. the ArrayController's
removeObjectAtArrangedIndex: method calls flagForDeletion, which for
most objects does nothing, but for the Bars properly updates Foo's
property and then flags them as trash so the setKey values won't
update.

I hate having the extra method, though. Is there any better approach I
can use? With in the constraints of the above caveats, of course.

-Jim...
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Binding Image and Text into a NSTextFieldCell

2009-04-24 Thread Arun
Hi All,

How can we place Image and text in a NSTextField cell.
I searched in the net and found sample codes for table columns with Image
and text.
Does any one know how to bind Image and Text into a NSTextFieldCell?

Thanks
Arun KA
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Core Data Fetches + Transient Properties + NSPredicateEditor = Sadness

2009-04-24 Thread Jerry Krinock


On 2009 Apr 23, at 13:53, Melissa J. Turner wrote:

Unwinding to the original message, the most correct thing to do  
would be to add a derived property letterGrade which is  
automatically updated whenever grade is, which then allows you to  
search against that.


Melissa, please give a more precise definition of derived property.   
Is it...


  (a) an attribute defined in the data model
   or (b) a plain old instance variable

Thanks,

Jerry

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Core Data and the Application Delegate

2009-04-24 Thread Sean McBride
On 4/23/09 8:37 PM, Jon Gordon said:

I'm having trouble understanding how to do certain things with the
application delegate in a document-based application that uses Core
Data. Or maybe I'm understanding things perfectly well, but I don't
like the logical conclusion.  But I digress.

In a normal (i.e., non-Core Data) document-based application, as I
understand it, one can modify certain functions by providing a
delegate to the instance of NSApplication.  For example, to keep the
application from opening a blank document at launch, I can have a
delegate that implements applicationShouldOpenUntitledFile: and always
returns NO.

But I understand (I think) also that, in a Core Data document-based
application, the application delegate is set to one provided by Core
Data.  And in such cases, providing my own delegate breaks Core Data
functionality that I'd otherwise get for free.

Am I right about this?

I don't believe so.  Why do you believe this?  In any case, you can
check yourself by asking NSApplication what its delegate is.

--

Sean McBride, B. Eng s...@rogue-research.com
Rogue Researchwww.rogue-research.com
Mac Software Developer  Montréal, Québec, Canada


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Core Data and the Application Delegate

2009-04-24 Thread Jason Foreman

On Apr 23, 2009, at 7:37 PM, Jon Gordon wrote:
But I understand (I think) also that, in a Core Data document-based  
application, the application delegate is set to one provided by Core  
Data.  And in such cases, providing my own delegate breaks Core Data  
functionality that I'd otherwise get for free.


The Core Data Application Xcode template does create an class that is  
hooked up as the application delegate.  However you are certainly free  
to add code to it or replace it with your own delegate, as long as  
your delegate also provides the functionality that the generated  
template delegate does (setting up Core Data stack, etc).  The default  
delegate isn't so much provided by Core Data as it is an default  
generated for you by Xcode.



Jason




smime.p7s
Description: S/MIME cryptographic signature
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Binding Image and Text into a NSTextFieldCell

2009-04-24 Thread Jerry Krinock


On 2009 Apr 24, at 11:55, Arun wrote:


Does any one know how to bind Image and Text into a NSTextFieldCell?


I don't believe you can do that with NSTextFieldCell.

I believe this would work:  First of all add or identify a single  
'foo' attribute in your data object model from which both data and  
text can be extracted.  Set up your bindings in the normal way:  Bind  
the table column's 'value' through an array controller to  
arrangedObjects.foo.  Then subclass NSCell, overriding - 
drawInteriorWithFrame:inView: to extract the image and text from - 
objectValue and draw them where you want them.  In the table column's - 
dataCellForRow:, return an instance of this NSCell subclass.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


problems with live resize of NSTextView

2009-04-24 Thread Stuart Malin
I have an NSTextView in a custom view, it is set to resize with the  
containing view only in the horizontal dimension. When I resize the  
window, the text view does resize, and it does re-layout its content  
to fit, both on expanding and shrinking. However, the text view not  
only changes its frame size height, but repositions itself (changing  
the y value of its frame's origin). Why does it do this?


More important to me: where is the best place for me to detect this  
change because I want to change the parent view's height to  
accommodate any increase in height in the text view.


TIA.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


KVO leaks memory

2009-04-24 Thread Andreas Grosam
I get strange memory leaks when I use KVO. The setup of all classes is  
OK as far as I can see, and the KVO is actually working. There is no  
memory leak when the classes will be tested in test cases without KVO.


There are two classes involved:
class Model and class Observer
Model has a property port where observer listens for change events.

The leak only occurs when KVO actually sends a change event.  
Otherwise, there are no leaks, even when KVO is established but no  
message has been sent. So it is quite probable that the source of the  
leak is within KVO code. The object leaking is obviously the receiver  
for the addObserver message, namely the model.


The leak is always only for one object and plus all the objects that  
are retained by model, no matter how often instances of Model will be  
created and KVO established.


For instance, doing this in a loop: creating observer and model,   
establish KVO, then causing a KVO event, tearing down everything --  
will only produce one leak from object model (plus the leaks from  
retained objects).


Here is the code for the observer that adds itself as an observer who  
listens at property port of model.


@implementation Observer
- (void) registerObserver
{
	[model addObserver:self forKeyPath:@port  
options:NSKeyValueObservingOptionNew context:NULL];

}


Here is the notification method for observer:
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
   change:(NSDictionary *)change context:(void  
*)context

{
NSDate *date = [NSDate date];
NSString *formattedDateString = [dateFormatter  
stringFromDate:date];

NSLog(@%@: %@, formattedDateString, keyPath);
}

The model spawns a thread who's run method installs a NSTimer  in the  
RunLoop. The timer handler then finally changes the value of property  
port of model. When the work is done, it is ensured, that the thread  
exits properly and releases all retained objects. After the thread  
function has been exited, the observer model and the observer will be  
released.


Note: The notification method observeValueForKeyPath will be invoked  
in a different thread than the main thread, where the KVO has been  
established.



The application runs currently in a Unit Test as a test case from the  
google toolbox for mac, on the iPhone. When the test case finishes,  
all objects should be deallocated.



So, what do I see here? Any thoughts what could cause the leaks?


Thanks for help

Regards
Andreas
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: KVO leaks memory

2009-04-24 Thread Andreas Grosam


On Apr 24, 2009, at 11:55 PM, Andreas Grosam wrote:

I get strange memory leaks when I use KVO. The setup of all classes  
is OK as far as I can see, and the KVO is actually working. There is  
no memory leak when the classes will be tested in test cases without  
KVO.


There are two classes involved:
class Model and class Observer
Model has a property port where observer listens for change events.

The leak only occurs when KVO actually sends a change event.  
Otherwise, there are no leaks, even when KVO is established but no  
message has been sent. So it is quite probable that the source of  
the leak is within KVO code. The object leaking is obviously the  
receiver for the addObserver message, namely the model.


The leak is always only for one object and plus all the objects that  
are retained by model, no matter how often instances of Model will  
be created and KVO established.


For instance, doing this in a loop: creating observer and model,   
establish KVO, then causing a KVO event, tearing down everything --  
will only produce one leak from object model (plus the leaks from  
retained objects).

Correction:
This statement is actually not correct. The number of leaks is  
almost proportional to the number of loops. However, some leaks  
seem to be reused or will not be detected.


This of course makes the thing much more worse.





Here is the code for the observer that adds itself as an observer  
who listens at property port of model.


@implementation Observer
- (void) registerObserver
{
	[model addObserver:self forKeyPath:@port  
options:NSKeyValueObservingOptionNew context:NULL];

}


Here is the notification method for observer:
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
  change:(NSDictionary *)change context:(void  
*)context

{
   NSDate *date = [NSDate date];
   NSString *formattedDateString = [dateFormatter  
stringFromDate:date];

   NSLog(@%@: %@, formattedDateString, keyPath);
}

The model spawns a thread who's run method installs a NSTimer  in  
the RunLoop. The timer handler then finally changes the value of  
property port of model. When the work is done, it is ensured, that  
the thread exits properly and releases all retained objects. After  
the thread function has been exited, the observer model and the  
observer will be released.


Note: The notification method observeValueForKeyPath will be invoked  
in a different thread than the main thread, where the KVO has been  
established.



The application runs currently in a Unit Test as a test case from  
the google toolbox for mac, on the iPhone. When the test case  
finishes, all objects should be deallocated.



So, what do I see here? Any thoughts what could cause the leaks?


Thanks for help

Regards
Andreas
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/agrosam%40onlinehome.de

This email sent to agro...@onlinehome.de


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Fill box with repeating text

2009-04-24 Thread Trygve Inda
I have a rect in a graphics context that I wish to fill with repeating text
Some Text so that the text repeats enough times to completely fill the
rect at the given line spacing, font style etc.

How can I determine how much text I need? Is there a better way to build
this than just stringByAppendingString a bunch of times?

Thanks,

Trygve


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Fill box with repeating text

2009-04-24 Thread Dave Keck
There are several ways to accomplish this.

(I'll note that you can get the size of an attributed string using its
-size method.)

Option 1: Create an NSImage with the size returned from the attributed
string. Draw the attributed string into the image. Create an NSColor
pattern from the image, using colorWithPatternImage:. Fill the rect
using [color set] and NSRectFill()/NSRectFillUsingOperation().

Option 2: you could alternatively go the slightly lower-level Core
Graphics route, and use CGContextDrawTiledImage(), which will draw a
tiled CGImage. I'm using this method in my personal code. I can't
remember why at the moment, but I may have run into limitations with
option 1. (Of course, I'd definitely try option 1 first as it'll be
easier.)

David
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: KVO leaks memory

2009-04-24 Thread Andreas Grosam


On Apr 25, 2009, at 1:07 AM, Jean-Daniel Dupas wrote:



Le 24 avr. 09 à 23:55, Andreas Grosam a écrit :

I get strange memory leaks when I use KVO. The setup of all classes  
is OK as far as I can see, and the KVO is actually working. There  
is no memory leak when the classes will be tested in test cases  
without KVO.


There are two classes involved:
class Model and class Observer
Model has a property port where observer listens for change events.

The leak only occurs when KVO actually sends a change event.  
Otherwise, there are no leaks, even when KVO is established but no  
message has been sent. So it is quite probable that the source of  
the leak is within KVO code. The object leaking is obviously the  
receiver for the addObserver message, namely the model.


The leak is always only for one object and plus all the objects  
that are retained by model, no matter how often instances of Model  
will be created and KVO established.


For instance, doing this in a loop: creating observer and model,   
establish KVO, then causing a KVO event, tearing down everything --  
will only produce one leak from object model (plus the leaks from  
retained objects).


Here is the code for the observer that adds itself as an observer  
who listens at property port of model.


@implementation Observer
- (void) registerObserver
{
	[model addObserver:self forKeyPath:@port  
options:NSKeyValueObservingOptionNew context:NULL];

}


Here is the notification method for observer:
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
 change:(NSDictionary *)change context:(void  
*)context

{
  NSDate *date = [NSDate date];
  NSString *formattedDateString = [dateFormatter  
stringFromDate:date];

  NSLog(@%@: %@, formattedDateString, keyPath);
}

The model spawns a thread who's run method installs a NSTimer  in  
the RunLoop. The timer handler then finally changes the value of  
property port of model. When the work is done, it is ensured, that  
the thread exits properly and releases all retained objects. After  
the thread function has been exited, the observer model and the  
observer will be released.


Note: The notification method observeValueForKeyPath will be  
invoked in a different thread than the main thread, where the KVO  
has been established.



The application runs currently in a Unit Test as a test case from  
the google toolbox for mac, on the iPhone. When the test case  
finishes, all objects should be deallocated.



So, what do I see here? Any thoughts what could cause the leaks?


Do you correctly remove the observer at the end ?

[model removeObserver:self forKeyPath:@port];


Yes, I did check this.

It turned out that KVO is not the culprit. For some unknown reason, it  
just significantly increased the chance of detecting leaks (from  
roughly 1:30 to 1:1). The actual cause was this:


model creates several other objects that will be stored in a  
dictionary which is also an ivar of model. The dictionary will be used  
as a parameter in a recursive method invocation, where its sub  
dictionaries will be processed.  Well, and it seemed practically to me  
(probably after a 14 hours day) to insert references to model to some  
sub-dictionaries at some point of the process. Unluckily, inserting an  
object increases its retain count, so the model retained itself  
through the dictionary  - and could never be dealloced  ;)

So, once I found the error, I could fix it in 5 seconds.

Just curious, if GC would solve this kind of self-referencing issue.


Thanks anyway :)

Regards
Andreas













___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Dividing NSView to subviews

2009-04-24 Thread Michael Ash
On Fri, Apr 24, 2009 at 8:02 AM, Naresh Kongara
naresh.kong...@prithvisolutions.com wrote:
 Thanks peter for your reply,

 Now there is some improvement in the performance , but the image is not that
 much clear as the image we are getting with dataWithPDFInsideRect:

 is there any way to remove that blur.

The technique that Peter showed will produce *exactly* the same pixels
that get rendered to the screen. If you have blur, it's either because
your view is blurry itself, or your drawing code is blurry. Either
way, we can't tell you what's going wrong unless you post your code.

Mike
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: ObjectAlloc and objects that should have been released

2009-04-24 Thread Miles
I just mean that I'm adding some labels and images to the view. I have
quadruple checked that they are all being released, but I must be
overlooking something.
For example, ObjectAlloc points to the second line here, where I declare
UIImage *logo as being created and still living, even though it's obviously
release right afterwards:

NSString *iconImageString= [[NSBundle mainBundle]
pathForResource:@big_logo
ofType:@png];
UIImage *logo= [[UIImage alloc]
initWithContentsOfFile:iconImageString];
UIImageView *logoView= [[UIImageView alloc] initWithImage: logo];
[logo release];
logoView.frame= CGRectMake(44, 32, 205, 32);

[self.view addSubview:logoView];
[logoView release];

There are a bunch of little things like this. And, none of these objects are
referenced from outside of this view controller -- only the creation and
destruction of the view controller.

Another one it points to is the line where I set the timer to nil:

+(void)stopToss {
if( tossTimer != nil ) {
[tossTimer invalidate];
tossTimer = nil;
}
}

Thoughts?


On Thu, Apr 23, 2009 at 11:12 PM, Alexander Spohr a...@freeport.de wrote:


 Am 24.04.2009 um 01:27 schrieb Miles:

  But when I run this in ObjectAlloc, a bunch of parts of the view are still
 showing as 'created and still living'. It's very odd considering the
 deallocs are both called so nothing should be hanging around.


 What is „a bunch of parts of the view“ in your case? You talk about two
 deallocs but „a bunch“ sounds more than two. Are you sure you release all
 retained vars in your dealloc?
 Maybe you have a cross-retain? (if you don’t use the GC).

atze


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Core Data and the Application Delegate

2009-04-24 Thread Jon Gordon
I believe it to be so because of some things I found while Googling to  
look for the answer.  I even found one poster to some list who claimed  
that his Core Data app worked perfectly well until he set his own  
application delegate, at which point it stopped working perfectly well.


On the other hand, though, I have put

NSLog(@delegate: %@, [NSApp delegate]);

statements at various points in my code, which is based on the  
Document-Based Core Data application template, and it always reports a  
null application delegate.  So now I'm full-on confused.


Thanks for the reply, though.

-Jon

On Apr 24, 2009, at 3:27 PM, Sean McBride wrote:


On 4/23/09 8:37 PM, Jon Gordon said:


I'm having trouble understanding how to do certain things with the
application delegate in a document-based application that uses Core
Data. Or maybe I'm understanding things perfectly well, but I don't
like the logical conclusion.  But I digress.

In a normal (i.e., non-Core Data) document-based application, as I
understand it, one can modify certain functions by providing a
delegate to the instance of NSApplication.  For example, to keep the
application from opening a blank document at launch, I can have a
delegate that implements applicationShouldOpenUntitledFile: and  
always

returns NO.

But I understand (I think) also that, in a Core Data document-based
application, the application delegate is set to one provided by Core
Data.  And in such cases, providing my own delegate breaks Core Data
functionality that I'd otherwise get for free.

Am I right about this?


I don't believe so.  Why do you believe this?  In any case, you can
check yourself by asking NSApplication what its delegate is.

--

Sean McBride, B. Eng s...@rogue-research.com
Rogue Researchwww.rogue-research.com
Mac Software Developer  Montréal, Québec, Canada




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Core Data and the Application Delegate

2009-04-24 Thread Jon Gordon


On Apr 24, 2009, at 4:40 PM, Jason Foreman wrote:


On Apr 23, 2009, at 7:37 PM, Jon Gordon wrote:
But I understand (I think) also that, in a Core Data document-based  
application, the application delegate is set to one provided by  
Core Data.  And in such cases, providing my own delegate breaks  
Core Data functionality that I'd otherwise get for free.


The Core Data Application Xcode template does create an class that  
is hooked up as the application delegate.  However you are certainly  
free to add code to it or replace it with your own delegate, as long  
as your delegate also provides the functionality that the generated  
template delegate does (setting up Core Data stack, etc).  The  
default delegate isn't so much provided by Core Data as it is an  
default generated for you by Xcode.


Thanks for the reply. I've seen this information about the existence  
of the default delegate elsewhere, but I can't seem to find any  
information about the delegate itself.  Indeed, whenever I ask NSApp  
what the delegate is (by using NSLog and [NSApp delegate]), it reports  
that the delegate is null.  I've tried searching the docs and Googling  
the Web, to no avail.  Do you know of any documentation for this?


Thanks again,
-Jon

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: KVO leaks memory

2009-04-24 Thread Greg Parker

On Apr 24, 2009, at 5:09 PM, Andreas Grosam wrote:
model creates several other objects that will be stored in a  
dictionary which is also an ivar of model. The dictionary will be  
used as a parameter in a recursive method invocation, where its sub  
dictionaries will be processed.  Well, and it seemed practically to  
me (probably after a 14 hours day) to insert references to model to  
some sub-dictionaries at some point of the process. Unluckily,  
inserting an object increases its retain count, so the model  
retained itself through the dictionary  - and could never be  
dealloced  ;)

So, once I found the error, I could fix it in 5 seconds.

Just curious, if GC would solve this kind of self-referencing issue.


Short answer: yes.

Any garbage collector worth the name will reclaim cycles of objects  
that point to each other, as long as none of them are referenced by  
any really live object. If there is no chain to the objects from  
global variables or the stack, then they'll die eventually.


Longer answer: yes, unless you build a trap using CFRetain or - 
[NSGarbageCollector disableCollectorForPointer].


Objective-C's garbage collector adds one more complication. Retain  
counts from CFRetain() still work: a CFRetained object will not be  
deleted. You can get into trouble if you have a cycle of objects, and  
one of them is CFRetained, and the balancing CFRelease() is in the  
finalizer of another object in the cycle. The finalizer won't get  
called because the object is referenced by a CFRetained object, and  
the CFRetained object won't get CFReleased because that other  
finalizer isn't called.



--
Greg Parker gpar...@apple.com Runtime Wrangler


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Core Data: thread safety of NSPersistentStore +metadataForPersistentStoreWithURL:... (and +set...)?

2009-04-24 Thread Jim Correia

I don't see that the documentation specifically calls out

@interface NSPersistentStore
+ (NSDictionary *)metadataForPersistentStoreWithURL:(NSURL *)url error: 
(NSError **)error;
+ (BOOL)setMetadata:(NSDictionary *)metadata forPersistentStoreWithURL: 
(NSURL*)url error:(NSError **)error;

@end

as being thread safe. (And in fact, these are abstract and need to be  
implemented by the concrete stores.)


(Outside of the obvious potential race condition) Is it intended that  
these methods are thread safe for Apple-supplied persistent stores  
(i.e. concurrently and/or non-main-thread callable)?


Jim

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Core Data and the Application Delegate

2009-04-24 Thread mmalc Crawford


On Apr 23, 2009, at 5:37 PM, Jon Gordon wrote:

In a normal (i.e., non-Core Data) document-based application, as I  
understand it, one can modify certain functions by providing a  
delegate to the instance of NSApplication.  For example, to keep the  
application from opening a blank document at launch, I can have a  
delegate that implements applicationShouldOpenUntitledFile: and  
always returns NO.



Yes.

But I understand (I think) also that, in a Core Data document-based  
application, the application delegate is set to one provided by Core  
Data.



No.

And in such cases, providing my own delegate breaks Core Data  
functionality that I'd otherwise get for free.



No.


Am I right about this?


No.

If so, what's the best way to make changes (like not opening the  
blank document at startup) that would, absent Core Data, be made by  
providing an application delegate?  And where's the best  
documentation for this?


What happened when you created a standard Core Data document-based  
application and added an application delegate that implemented  
applicationShouldOpenUntitledFile:?


mmalc

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: passing complex objects between threads

2009-04-24 Thread Eric Hermanson
I believe you should use a producer-consumer pattern where the  
consumer thread waits on a blocking queue for the incoming object, and  
the producer thread passes the fetched object to the blocking queue  
after its fetched.  There are many examples of producer/consumer on  
the web...


- Eric


On Apr 24, 2009, at 9:24 PM, Daniel Child wrote:

I have a Core Data app that imports data via a separate managed  
object contexts. Without multithreading, the operation works fine.  
But since the import takes over a minute, I want to do the import in  
a different thread. The data consists of an archived table of data  
with records.


This is my first time attempting to use threads, and the basic  
problem I'm having is figuring out the best way to pass the complex  
object (the table of records) from one thread to another. Since  
there are something like 50,000 records, deep-copying would be ugly.


I thought of three workarounds.

1. Unarchive the table to be parsed while in the second thread so  
you have the original, not a copy. Should work, but it's kind of  
skirting the issue.


2. Create a global variable and copy the table into it . I tried  
this, but the table's records ivar is still not deep-copied.


3. The thread is called by the app controller with thread's owner  
set to the app controller itself. i.e. (void) doImportThread: (id)  
owner [== self / appController]. Theoretically, I should be able to  
cache the table as appController ivar and access it from within the  
thread as [owner tableToParse]. I tried this too, and just as with  
the global variable approach, the actual records are not available  
within the second thread, only the simple ivars.


This must be a common issue with multithreading. Is there an elegant  
way to get access to deeper layers of a complex object from within  
another thread? i.e. a way to make 2) or 3) above work?


Thanks.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/zmonster%40mac.com

This email sent to zmons...@mac.com


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


parsing a string into words

2009-04-24 Thread Gerriet M. Denkmann


I want to parse a string into words.
Currently I do:

NSString *theString = 
NSUInteger stringLength = [ theString length ];
NATextView *theTextView = [[NSTextView alloc] initWithFrame:  
NSMakeRect(0,0,99,99) ];

[ theTextView setString: theString ];

for( NSUInteger t = 0; t  stringLength;)
{
NSRange proposedSelRange = NSMakeRange(t,0);
	NSRange wordRange = [ theTextView 	selectionRangeForProposedRange:  
proposedSelRange


granularity:NSSelectByWord
];
NSString *word = [ theString substringWithRange: wordRange ];
t = NSMaxRange( wordRange );

//  do something with word
};

[ theTextView release ];

but this looks rather wasteful. Is there a more elegant way?

Please note that there are lots of languages, where words are not  
separated by space or punctuation.



Kind regards,

Gerriet.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: ObjectAlloc and objects that should have been released

2009-04-24 Thread Peter N Lewis

On 25/04/2009, at 8:28 , Miles wrote:

I just mean that I'm adding some labels and images to the view. I have
quadruple checked that they are all being released, but I must be
overlooking something.


I doubt its your issue, but I recently had a problem like this that  
took me far too long to track down.


The debugging technique I used was to override retain/release/ 
autorelease and dealloc and have them just call NSLog and super, then  
set a breakpoint on each, add a backtrace bt debugging command and  
set them to auto-continue.


Eventually, after much hair pulling I tracked it down to my  
removeFromSuperview override neglecting to call super - ouch!


But one technique for finding this might be to make a trivial subclass  
of UIImage that does the above and use it for logo.


One other possibility would be - does UIImage cache images created  
with initWithContentsOfFile?  The tehcnique above might tell you if  
thats what is happening, because you should see UIImage system code  
adding it to an array/dictiuonary/set and not releasing it later.


Enjoy,
   Peter.

--
 Run macros from your iPhone with Keyboard Maestro Control!
 or take a break with Derzle for your iPhone

Keyboard Maestro http://www.keyboardmaestro.com/ Macros for your Mac
Aragom Space War http://www.stairways.com/iphone/aragom Don't get  
killed!

Derzle http://www.stairways.com/iphone/derzle Enjoy a relaxing puzzle.
http://www.stairways.com/   http://download.stairways.com/




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: parsing a string into words

2009-04-24 Thread Michael Ash
On Fri, Apr 24, 2009 at 9:24 PM, Gerriet M. Denkmann
gerr...@mdenkmann.de wrote:

 I want to parse a string into words.
 Currently I do:

 NSString *theString = 
 NSUInteger stringLength = [ theString length ];
 NATextView *theTextView = [[NSTextView alloc] initWithFrame:
 NSMakeRect(0,0,99,99) ];
 [ theTextView setString: theString ];

 for( NSUInteger t = 0; t  stringLength;)
 {
        NSRange proposedSelRange = NSMakeRange(t,0);
        NSRange wordRange = [ theTextView
 selectionRangeForProposedRange: proposedSelRange

    granularity:                                    NSSelectByWord
                                                ];
        NSString *word = [ theString substringWithRange: wordRange ];
        t = NSMaxRange( wordRange );

        //      do something with word
 };

 [ theTextView release ];

 but this looks rather wasteful. Is there a more elegant way?

 Please note that there are lots of languages, where words are not separated
 by space or punctuation.

If you can require 10.5, use CFStringTokenizer. It is really great,
and is a lot simpler and less evil than this.

Mike
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: ObjectAlloc and objects that should have been released

2009-04-24 Thread Miles
Very interesting, I'll give all that a shot and report back. Thanks so  
much!




On Apr 24, 2009, at 7:07 PM, Peter N Lewis pe...@stairways.com.au  
wrote:



On 25/04/2009, at 8:28 , Miles wrote:
I just mean that I'm adding some labels and images to the view. I  
have

quadruple checked that they are all being released, but I must be
overlooking something.


I doubt its your issue, but I recently had a problem like this that  
took me far too long to track down.


The debugging technique I used was to override retain/release/ 
autorelease and dealloc and have them just call NSLog and super,  
then set a breakpoint on each, add a backtrace bt debugging  
command and set them to auto-continue.


Eventually, after much hair pulling I tracked it down to my  
removeFromSuperview override neglecting to call super - ouch!


But one technique for finding this might be to make a trivial  
subclass of UIImage that does the above and use it for logo.


One other possibility would be - does UIImage cache images created  
with initWithContentsOfFile?  The tehcnique above might tell you if  
thats what is happening, because you should see UIImage system code  
adding it to an array/dictiuonary/set and not releasing it later.


Enjoy,
  Peter.

--
Run macros from your iPhone with Keyboard Maestro Control!
or take a break with Derzle for your iPhone

Keyboard Maestro http://www.keyboardmaestro.com/ Macros for your Mac
Aragom Space War http://www.stairways.com/iphone/aragom Don't get  
killed!
Derzle http://www.stairways.com/iphone/derzle Enjoy a relaxing  
puzzle.

http://www.stairways.com/   http://download.stairways.com/




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/vardpenguin%40gmail.com

This email sent to vardpeng...@gmail.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Fill box with repeating text

2009-04-24 Thread Trygve Inda
 There are several ways to accomplish this.
 
 (I'll note that you can get the size of an attributed string using its
 -size method.)
 
 Option 1: Create an NSImage with the size returned from the attributed
 string. Draw the attributed string into the image. Create an NSColor
 pattern from the image, using colorWithPatternImage:. Fill the rect
 using [color set] and NSRectFill()/NSRectFillUsingOperation().
 
 Option 2: you could alternatively go the slightly lower-level Core
 Graphics route, and use CGContextDrawTiledImage(), which will draw a
 tiled CGImage. I'm using this method in my personal code. I can't
 remember why at the moment, but I may have run into limitations with
 option 1. (Of course, I'd definitely try option 1 first as it'll be
 easier.)
 
 David
 

Hi David,

This is pretty close:

NSImage*  theImage = [[NSImage alloc] initWithSize:[theString size]];

[theImage lockFocus];
[theString drawAtPoint:NSZeroPoint];
[theImage unlockFocus];

But I end up with black text on a white background. Adding:

NSColor*textColor  = [NSColor colorWithDeviceRed:0.0 green:0.0 blue:0.0
alpha:0.50];

NSDictionary*   textAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
textColor, NSForegroundColorAttributeName, nil];

NSAttributedString*theString = [[NSAttributedString alloc]
initWithString:@myText attributes:textAttributes];

Makes the text transparent, but I can't seem to make the background of the
NSImage transparent. I want to end up with white text on a transparent
background, but [[NSImage alloc] initWithSize:[theString size]] seems to set
the background to solid white.

How can I fix this?

Thanks,

Trygve


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Fill box with repeating text

2009-04-24 Thread Dave Keck
 Makes the text transparent, but I can't seem to make the background of the
 NSImage transparent. I want to end up with white text on a transparent
 background, but [[NSImage alloc] initWithSize:[theString size]] seems to set
 the background to solid white.

This is because you're drawing the image incorrectly for your purposes. If you:

[[theImage TIFFRepresentation] writeToFile: [@~/Desktop/halla.tiff
stringByExpandingTildeInPath] atomically: YES];

That'll write the image to your desktop. Open it in Preview or
something, and you'll see that the background is, in fact,
transparent. What you want to do instead is use a different
compositing operation when you draw the image. NSCompositeSourceOver
is most likely what you want:

[theImage drawAtPoint: NSZeroPoint fromRect: NSZeroRect operation:
NSCompositeSourceOver fraction: 1.0];

David
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Fill box with repeating text

2009-04-24 Thread Chris Suter
Hi Trygve,

2009/4/25 Trygve Inda cocoa...@xericdesign.com

Makes the text transparent, but I can't seem to make the background of the
 NSImage transparent. I want to end up with white text on a transparent
 background, but [[NSImage alloc] initWithSize:[theString size]] seems to
 set
 the background to solid white.

 How can I fix this?


It won't necessarily be initWithSize that sets the background to white. It's
more likely the lockFocus call which causes an NSCachedImageRep to be
created. Now I'm not sure how you can change it so that it creates a clear
background by default, but you can easily fix the background by calling
NSRectFillWithOperation(rect, NSCompositeClear) just after you've locked
focus on the image.

Regards,

Chris
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Fill box with repeating text

2009-04-24 Thread Trygve Inda
 Makes the text transparent, but I can't seem to make the background of the
 NSImage transparent. I want to end up with white text on a transparent
 background, but [[NSImage alloc] initWithSize:[theString size]] seems to set
 the background to solid white.
 
 This is because you're drawing the image incorrectly for your purposes. If
 you:
 
 [[theImage TIFFRepresentation] writeToFile: [@~/Desktop/halla.tiff
 stringByExpandingTildeInPath] atomically: YES];
 
 That'll write the image to your desktop. Open it in Preview or
 something, and you'll see that the background is, in fact,
 transparent. What you want to do instead is use a different
 compositing operation when you draw the image. NSCompositeSourceOver
 is most likely what you want:
 
 [theImage drawAtPoint: NSZeroPoint fromRect: NSZeroRect operation:
 NSCompositeSourceOver fraction: 1.0];

Where does this go as it is drawing the image, not the text? The image is
drawn with a RectFill call??

Trygve


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSPopUpButtonCell causes UI to sleep when clicked

2009-04-24 Thread Jerry Krinock


On 2009 Apr 24, at 17:36, Peter Ammon wrote:

Sorry, I think I misread your original message.  After the menu is  
dismissed, then the run loop should return to the Default mode and  
timers in that mode should resume.  The behavior you describe is  
pretty weird.


Thank you, Peter.  I had been preparing a reply, but now it will be  
shorter.


Can you take a sample of the app when it is in this state? What does  
it show?


Yes, I did that yesterday, just recreated and saved one for you [1].   
In the first thread, -[NSTableHeaderView mouseDown:], is when I click  
the mouse in a table header view to which the menu is attached.




I tried to reproduce the problem in a demo project, like this:

[[popUp cell] performClickWithFrame:[sender frame]
 inView:sender] ;

where 'sender' is a regular button instead of a NSTableHeaderView as  
in my real project.  But in the demo project, tracking stops when the  
menu is closed.


On 2009 Apr 24, at 15:02, Peter Ammon wrote:

This method [attachPopUpWithFrame:inView] is mainly a holdover from  
NeXT menus, and isn't good for much.


Great.  I just submitted Document Feedback requesting that your remark  
be added to the documentation, because it would have saved me quite  
some time.  It will be interesting to see how the marketing guys  
translate it ;)


If you want to pop up a popup button, you can use either  
performClick: or trackMouse:inRect:ofView:untilMouseUp:


The latter can only be used if you have the event, so I am using the  
performClick:inView:.  I just tried using performClick: as you  
suggest, but the menu fails to pop up.


If you have any clues as to what I might have done to cause this menu  
to continue event tracking after it has been closed, let me know -- it  
might save me a few hours of trial and error in converging my bad  
and good cases.


Jerry



[1]

Sampling process 30384 for 3 seconds with 1 millisecond of run time  
between samples

Sampling completed, processing symbols...
Analysis of sampling New Project (pid 30384) every 1 millisecond
Call graph:
2020 Thread_2507
  2020 start
2020 main
  2020 NSApplicationMain
2020 -[NSApplication run]
  2020 -[NSApplication sendEvent:]
2020 -[NSWindow sendEvent:]
  2020 -[NSTableHeaderView mouseDown:]
2020 -[NSTableHeaderView  
_trackAndModifySelectionWithEvent:onColumn:stopOnReorderGesture:]

  2020 -[NSWindow nextEventMatchingMask:]
2020 -[NSApplication  
nextEventMatchingMask:untilDate:inMode:dequeue:]

  2020 _DPSNextEvent
2020 BlockUntilNextEventMatchingListInMode
  2020 ReceiveNextEventCommon
2020 RunCurrentEventLoopInMode
  2020 CFRunLoopRunInMode
2020 CFRunLoopRunSpecific
  2019 mach_msg
2019 mach_msg_trap
  2019 mach_msg_trap
  1 DisposeAllMenuWindows()
1 ForEachMenuDo(long (*) 
(MenuData*, void*), void*)

  1 CFDictionaryApplyFunction
1  
Dispose1MenuWindow(MenuData*, void*)

  1 _CFRelease
1  
WindowData::Destruct()
  1  
HIObject::Destruct()
1  
SendEventToEventTargetWithOptions
  1  
SendEventToEventTargetInternal(OpaqueEventRef*, OpaqueEventTargetRef*,  
HandlerCallRec*)
1  
DispatchEventToHandlers(EventTargetRec*, OpaqueEventRef*,  
HandlerCallRec*)
  1  
HIObject::EventHook(OpaqueEventHandlerCallRef*, OpaqueEventRef*, void*)
1  
HIObject::HandleClassHIObjectEvent(OpaqueEventHandlerCallRef*,  
OpaqueEventRef*, void*)
  1  
HIViewWrapperDef::~HIViewWrapperDef()
1  
WindowData::~WindowData()
  1  
DisposePlatformWindow
1  
CGSReleaseWindow
   
1 _CGSReleaseWindowList
1 
 _CGSTerminateWindowList
 

Re: Fill box with repeating text

2009-04-24 Thread Dave Keck
 Where does this go as it is drawing the image, not the text? The image is
 drawn with a RectFill call??

Ah, sorry. I meant to say:

NSRectFillUsingOperation(rect, NSCompositeSourceOver);

Note that point here is that however the image is finally drawn, you
have to make sure you're drawing it using the 'NSCompositeSourceOver'.
NSRectFill will implicitly use NSCompositeCopy (as the docs mention).

Does that do the trick?

David
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Core Data and the Application Delegate

2009-04-24 Thread Andy Lee

On Apr 24, 2009, at 8:47 PM, Jon Gordon wrote:

On Apr 24, 2009, at 4:40 PM, Jason Foreman wrote:


On Apr 23, 2009, at 7:37 PM, Jon Gordon wrote:
But I understand (I think) also that, in a Core Data document- 
based application, the application delegate is set to one provided  
by Core Data.  And in such cases, providing my own delegate breaks  
Core Data functionality that I'd otherwise get for free.


The Core Data Application Xcode template does create an class that  
is hooked up as the application delegate.  However you are  
certainly free to add code to it or replace it with your own  
delegate, as long as your delegate also provides the functionality  
that the generated template delegate does (setting up Core Data  
stack, etc).  The default delegate isn't so much provided by Core  
Data as it is an default generated for you by Xcode.


Thanks for the reply. I've seen this information about the existence  
of the default delegate elsewhere, but I can't seem to find any  
information about the delegate itself.  Indeed, whenever I ask NSApp  
what the delegate is (by using NSLog and [NSApp delegate]), it  
reports that the delegate is null.  I've tried searching the docs  
and Googling the Web, to no avail.  Do you know of any documentation  
for this?


I haven't used Core Data, but I see there are two Xcode templates that  
give you different things.  If you create a Core Data *Document- 
based* Application, no app delegate is created for you.  If you  
create a Core Data Application, an app delegate class is created and  
you can see the .h and .m files in Xcode.  Anything you read about a  
delegate being created for you was probably referring to the latter  
case.


--Andy


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: passing complex objects between threads

2009-04-24 Thread Chris Hanson

On Apr 24, 2009, at 6:24 PM, Daniel Child wrote:

I have a Core Data app that imports data via a separate managed  
object contexts. Without multithreading, the operation works fine.  
But since the import takes over a minute, I want to do the import in  
a different thread. The data consists of an archived table of data  
with records.


This is my first time attempting to use threads, and the basic  
problem I'm having is figuring out the best way to pass the complex  
object (the table of records) from one thread to another. Since  
there are something like 50,000 records, deep-copying would be ugly.


Indeed.  Furthermore, since you're working with Core Data, you may not  
actually want those 50K objects passed from one thread to another;  
Core Data strongly prefers threads to work in entirely separate  
managed object contexts.  If you use one NSManagedObjectContext per  
thread, but these contexts use the same NSPersistentStoreCoordinator,  
Core Data has just the solution for you.


This must be a common issue with multithreading. Is there an elegant  
way to get access to deeper layers of a complex object from within  
another thread? i.e. a way to make 2) or 3) above work?


In fact, you can probably get away with not passing the objects  
across to the main thread at all.  Since your user interface will be  
fed from the managed object context you've created for the main  
thread — whether you're using bindings or doing your user interface  
manually — and you can set that context to use the same coordinator as  
your background thread, you can just do appropriate fetches and  
relationship traversals against the main thread's context to build up  
the object graph you're actually presenting to the user.


If you do want to still pass information from the background thread to  
the main thread, all you need to pass are the managed object IDs of  
the (saved) objects the main thread will be interested in.  You can  
just use -[NSObject  
performSelectorOnMainThread:withObject:waitUntilDone:] for this and  
pass either individual object IDs or collections of them.  Then on the  
main thread, you can ask the main thread's managed object context for  
the managed object with that ID, and it'll hand you back an  
appropriate one that you can use for your user interface.


  -- Chris

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Fill box with repeating text

2009-04-24 Thread Trygve Inda
 Where does this go as it is drawing the image, not the text? The image is
 drawn with a RectFill call??
 
 Ah, sorry. I meant to say:
 
 NSRectFillUsingOperation(rect, NSCompositeSourceOver);
 
 Note that point here is that however the image is finally drawn, you
 have to make sure you're drawing it using the 'NSCompositeSourceOver'.
 NSRectFill will implicitly use NSCompositeCopy (as the docs mention).
 
 Does that do the trick?
 
 David
 

Indeed it does. Many thanks!

Trygve


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: CF autorelease?

2009-04-24 Thread Charles Srstka

On Apr 23, 2009, at 3:42 PM, Todd Heberlein wrote:

Many of the Cocoa object allocation methods automatically do an  
autorelease before returning the pointer to the object, so I can  
call something like:


foo( [NSString stringWithCString: bar encoding:  
NSASCIIStringEncoding] );


and then not worry about memory leakage. Is the same true with Core  
Foundation calls? For example, will


foo2( CFSTR(bar) ); or
foo2 ( CFStringCreateWithCString(NULL, bar,  
kCFStringEncodingASCII) );


leak memory?


You could just:

foo2 ( [(NSString *)CFStringCreateWithCString(NULL, bar,  
kCFStringEncodingASCII) autorelease] );


Charles
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com