Re: Using runtime functions to match up object types safely when setting properties
On 19 Dec 08, at 19:28, Ken Thomases wrote: I think your only avenue is to implement explicit KVV methods for your properties which have the necessary knowledge to test their type. I suppose you could file a feature request to extend declared properties so they can synthesize a type-checking validation method. Or request a compile-time directive to determine the static type of a method return or a property. (Hmm. gcc has a "typeof" extension. I wonder if it works in Objective-C.) I'm pretty sure that typeof is, like sizeof, purely a compile-time directive. All it'll do when applied to an object pointer is return the declared type of the pointer. However, I think you've overengineering things here. The standard runtime introspection methods, like [NSObject class] and [NSObject isKindOfClass:], should be more than enough to implement this sort of functionality. ___ 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: Using runtime functions to match up object types safely when setting properties
On 20 Dec 2008, at 8:05 pm, Andrew Farmer wrote: However, I think you've overengineering things here. The standard runtime introspection methods, like [NSObject class] and [NSObject isKindOfClass:], should be more than enough to implement this sort of functionality. You might be right about the overengineering, but -class and - isKindOfClass: can't be used on methods, only on objects you already have. If you have an object that has a property setter, e.g. - (void)setColor:(NSColor*) aColor; and you have a variable selector that can refer to that (but also potentially many other) methods, and an object that might, or might not, be an NSColor*, how do you make sure you don't end up sending that method a string? KVV works pretty well for this - it also solves another related situation where I can usefully convert objects to other types in some cases - but what I still haven't quite worked out yet is how to *prevent* the situation arising in the first place, in other words, given a list of methods, and an object class, how to filter out those methods/properties from a list that can't accept the object. --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: Newbie Question: implementing a stack
Sorry to jump in to this a little late, but a guy in our CocoaHeads group wrote a framework as part of his Master's thesis work. It's a datastructure framework and contains a bunch of datastructures not available (publicly) in Cocoa, such as stacks, queues, dequeues, avl/ rb/aa-trees, treaps, etc. It's open sourced under the LGPL license, and you can check it out of svn from our CocoaHeads page on it: http://cocoaheads.byu.edu/code/CHDataStructures Cheers, Dave On 19 Dec, 2008, at 12:22 PM, Steve Wetzel wrote: Hi All, I am new to this list and new to mac programming as well. I am working on implementing a stack as a category of NSMutableArray. I want this stack to be able to store objects. This is what I have so far: // // Stack.h // Stack implements a basic stack object in an NSMutableArray object. #import @interface NSMutableArray (Stack) -(void)push:(id)obj;//push obj of on the stack -(id)pop; //pop top item off the stack -(id)peek; //look at the top item on the stack -(void)clear; //remove all objects from the stack -(NSUInteger)size; //return the number of items on the stack @end // // Stack.m // Stack #import "Stack.h" @implementation NSMutableArray (Stack) -(void)push:(id)obj { [self addObject:obj]; } -(id)pop { id popedObj; if([self count]) { popedObj = [[[self lastObject] retain] autorelease]; [self removeLastObject]; } else { popedObj = nil; } return popedObj; } -(id)peek; //look at the top item on the stack { return [self lastObject]; } -(void)clear; //remove all objects from the stack { [self removeAllObjects]; } -(NSUInteger)size; //return the number of items on the stack { return [self count]; } @end My question involves storing objects on the stack. As I understand it when I store an object on the stack, I am simply storing a pointer to the object on the stack. If I create an NSString object called foo and do the following: NSString *foo = [[NSString alloc] initWithString:@"foo text"]; [FractionStack push:foo]; I have put a copy of the pointer to foo on the stack. If I now change foo, the top element on the stack changes also. I do not want this to happen but I am not sure as to the best approach to make sure this does not happen. Would it be best to copy the object to another object - say fooCopy then push fooCopy on the stack? Or would it be better to copy the object inside of the push method? And either way, I am struggling with memory management. If I first copy foo to fooCopy before placing it on the stack then I release fooCopy, will the element on the stack still be able to reference it? do I need to retain it in my push method? Also, I am thinking I likely will need to release these objects when I pop them and when I clear the stack. Is that correct? I am really trying to get my head wrapped around this but I have been struggling with this for some time. If, in addition to some words of wisdom, you can point me in the direction of how I could create a simple test of this in my code to work things out on my own that would be appreciated also. As I said I am new to this so if my post is not in keeping with the way things work on this list please let me know. Thanks in advance, 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/davedelong%40me.com This email sent to davedel...@me.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: Question Regarding the Memory Address of Objects
I have a concern that the direct use of a pointer as a memory address may have a problem in the case of GC. In Java, object reference is not a simple memory address because objects may be moved by GC. Does Cocoa has a GC implementation avoid it? 2008/12/19 Carter R. Harrison : > > On Dec 18, 2008, at 3:44 PM, David Duncan wrote: > >> On Dec 18, 2008, at 11:57 AM, Carter R. Harrison wrote: >> >>>[dict setValue:@"button1" forKey:[NSString stringWithFormat:@"%x", >>> &button1]]; // "button1" is one of my IBOutlets. >>>NSString *value = [dict valueForKey:[NSString >>> stringWithFormat:@"%x", &sender]]; >>> >>> It seems like the memory address of the sender is different than what it >>> should be. I did some debugging and the address of the sender is always >>> bfffe2e8 which really shouldn't be possible at all. >> >> >> Your confusing the pointer with the object itself. button1 is a pointer to >> a button. sender is a pointer to the object that sent the message. When you >> take the address of either pointer, you get the location of that pointer in >> memory - not the location of the object. The pointer itself contains the >> location of the object in memory. >> -- >> David Duncan >> Apple DTS Animation and Printing >> > > David, > > Once again you have saved me from pulling my hair out. Thank you once again > for your assistance. For the rest of the folks on the thread the solution > was to remove the "&" from the front of all my pointers. > > Regards, > Carter > ___ > > 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/middle.fengdong%40gmail.com > > This email sent to middle.fengd...@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: Question Regarding the Memory Address of Objects
The objective-c garbage collector does not move objects, so that is not an issue with using raw pointers. Sent from my iPhone On Dec 20, 2008, at 6:50, "Dong Feng" wrote: I have a concern that the direct use of a pointer as a memory address may have a problem in the case of GC. In Java, object reference is not a simple memory address because objects may be moved by GC. Does Cocoa has a GC implementation avoid it? 2008/12/19 Carter R. Harrison : On Dec 18, 2008, at 3:44 PM, David Duncan wrote: On Dec 18, 2008, at 11:57 AM, Carter R. Harrison wrote: [dict setValue:@"button1" forKey:[NSString stringWithFormat:@"%x", &button1]]; // "button1" is one of my IBOutlets. NSString *value = [dict valueForKey:[NSString stringWithFormat:@"%x", &sender]]; It seems like the memory address of the sender is different than what it should be. I did some debugging and the address of the sender is always bfffe2e8 which really shouldn't be possible at all. Your confusing the pointer with the object itself. button1 is a pointer to a button. sender is a pointer to the object that sent the message. When you take the address of either pointer, you get the location of that pointer in memory - not the location of the object. The pointer itself contains the location of the object in memory. -- David Duncan Apple DTS Animation and Printing David, Once again you have saved me from pulling my hair out. Thank you once again for your assistance. For the rest of the folks on the thread the solution was to remove the "&" from the front of all my pointers. Regards, Carter ___ 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/middle.fengdong%40gmail.com This email sent to middle.fengd...@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/clarkcox3%40gmail.com This email sent to clarkc...@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
Sorting an NSMutableArray
How do you sort an NSMutableArray, when the difference between the two objects is determined by information not contained completely within the objects themselves. ie in Java you can implement a Comparator that takes two objects to compare then. Is this similar in Cocoa? ie in this case I need to apply a mathematical algorithm using information from each object to determine which one is greater than the other. Thanks! Jacob http://jacobrhoden.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: Sorting an NSMutableArray
On Dec 20, 2008, at 6:15 AM, Jacob Rhoden wrote: How do you sort an NSMutableArray, when the difference between the two objects is determined by information not contained completely within the objects themselves. ie in Java you can implement a Comparator that takes two objects to compare then. Is this similar in Cocoa? ie in this case I need to apply a mathematical algorithm using information from each object to determine which one is greater than the other. See sortUsingSelector: What I then personally do is to create a "Sorting" category on whatever object it is that the collection will contain. For example: @interface MyObject (Sorting) - (NSComparisonResult)myCustomCompare:(MyObject*)rhs; @end Then, LHS is self and RHS is the param coming in. ___ Ricky A. Sharp mailto:rsh...@instantinteractive.com Instant Interactive(tm) http://www.instantinteractive.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: Listening for changes
Thanks for the idea Mike. Not sure how I could implement this without sending the notification in every setter of the class though... Andre Masse On Dec 19, 2008, at 19:24, Mike Abdullah wrote: Since you apparently want to just know that one of the fields changed, but not which one specifically, why not just have the class post an NSNotification called MyClassDidChange or similar? 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: Optimizing NSRectFill
Here is how I arrived at the conclusion that NSRectFill is the bottleneck. (I cannot show the code because it's spread over objects). The slowness of redraw is only noticeable when I drag the mouse, e.g. to resize an object in the custom view. I see that update of the resized object is always late after the actual position of the mouse pointer, and the latency is sometimes pretty great to not be excused. Especially when the size of the rectangle to be updated is large. My custom view supports zooming, so I call NSRectFill after setting an NSAffineTransform. Larger zooms, as I said, seem to cause greater latency. Sometimes I also use clipping ([NSBezierPath addClip]) before calling NSRectFill. I never call -[NSView displayIfNeeded] or use other ways of forcing the view to update itself. I always rely on -[NSView setNeedsDisplayInRect:] to invalidate the rectangle(s) that need to be updated and then wait until the next refresh. What is true, that -[NSView setNeedsDisplayInRect:] are often called multiple times for the same rectangles, but I don't think it matters. I run my app with the Shark tool and drag the mouse to resize an object, to and fro, for few seconds, then check the sample. It always shows that 20-30% of time is taken by the NSRectFill function, which is called only once to simply draw the background of the view with solid white! This is ridiculous. I tried to put an NSLog near the NSRectFill call to check if it is called extra times, but it seems that it is being called exactly one time per single mouse drag message. When I comment out the call to NSRectFill, then the refresh becomes noticeably smoother, and the Shark gives leadership to other bottlenecks, in my case the NSBezierPath stroke and fill messages, for the objects drawn in the view. Any ideas? On Sat, Dec 20, 2008 at 1:45 AM, Peter Ammon wrote: > > On Dec 19, 2008, at 7:37 AM, Oleg Krupnov wrote: > >> I'm developing a custom view and noticed that drawRect is becoming >> increasingly slow. The Shark has pointed out that the bottleneck is >> the NSRectFill function (that calls CGContextFillRect under the hood) >> that I use to draw the background of the view. > > A common cause of apparently excessive time in graphics related ops is that > you are running afoul of coalesced updates by attempting to refresh faster > than 60 times a second. > > See > http://developer.apple.com/documentation/Performance/Conceptual/Drawing/Articles/FlushingContent.html > . > Try disabling coalesced updates in Quartz Debug and see if it speeds up > your drawing. If so, ensure your app does not refresh faster than 60 Hz. > > -Peter > > ___ 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: Optimizing NSRectFill
Le 20 déc. 08 à 15:22, Oleg Krupnov a écrit : Here is how I arrived at the conclusion that NSRectFill is the bottleneck. (I cannot show the code because it's spread over objects). The slowness of redraw is only noticeable when I drag the mouse, e.g. to resize an object in the custom view. I see that update of the resized object is always late after the actual position of the mouse pointer, and the latency is sometimes pretty great to not be excused. Especially when the size of the rectangle to be updated is large. My custom view supports zooming, so I call NSRectFill after setting an NSAffineTransform. Larger zooms, as I said, seem to cause greater latency. Sometimes I also use clipping ([NSBezierPath addClip]) before calling NSRectFill. I never call -[NSView displayIfNeeded] or use other ways of forcing the view to update itself. I always rely on -[NSView setNeedsDisplayInRect:] to invalidate the rectangle(s) that need to be updated and then wait until the next refresh. What is true, that -[NSView setNeedsDisplayInRect:] are often called multiple times for the same rectangles, but I don't think it matters. I run my app with the Shark tool and drag the mouse to resize an object, to and fro, for few seconds, then check the sample. It always shows that 20-30% of time is taken by the NSRectFill function, which is called only once to simply draw the background of the view with solid white! This is ridiculous. I tried to put an NSLog near the NSRectFill call to check if it is called extra times, but it seems that it is being called exactly one time per single mouse drag message. When I comment out the call to NSRectFill, then the refresh becomes noticeably smoother, and the Shark gives leadership to other bottlenecks, in my case the NSBezierPath stroke and fill messages, for the objects drawn in the view. Any ideas? On Sat, Dec 20, 2008 at 1:45 AM, Peter Ammon wrote: On Dec 19, 2008, at 7:37 AM, Oleg Krupnov wrote: I'm developing a custom view and noticed that drawRect is becoming increasingly slow. The Shark has pointed out that the bottleneck is the NSRectFill function (that calls CGContextFillRect under the hood) that I use to draw the background of the view. A common cause of apparently excessive time in graphics related ops is that you are running afoul of coalesced updates by attempting to refresh faster than 60 times a second. See http://developer.apple.com/documentation/Performance/Conceptual/Drawing/Articles/FlushingContent.html . Try disabling coalesced updates in Quartz Debug and see if it speeds up your drawing. If so, ensure your app does not refresh faster than 60 Hz. -Peter ___ 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/devlists%40shadowlab.org This email sent to devli...@shadowlab.org ___ 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: Optimizing NSRectFill
Sorry for the blank previous mail. Try to call NSFillRect with the rect pased as parameter in drawRect: and before applying the scaling method. As the rect parameter contains the invalid rect in screen coordinates, you don't have to transform it before filling the rect with white. Le 20 déc. 08 à 15:22, Oleg Krupnov a écrit : Here is how I arrived at the conclusion that NSRectFill is the bottleneck. (I cannot show the code because it's spread over objects). The slowness of redraw is only noticeable when I drag the mouse, e.g. to resize an object in the custom view. I see that update of the resized object is always late after the actual position of the mouse pointer, and the latency is sometimes pretty great to not be excused. Especially when the size of the rectangle to be updated is large. My custom view supports zooming, so I call NSRectFill after setting an NSAffineTransform. Larger zooms, as I said, seem to cause greater latency. Sometimes I also use clipping ([NSBezierPath addClip]) before calling NSRectFill. I never call -[NSView displayIfNeeded] or use other ways of forcing the view to update itself. I always rely on -[NSView setNeedsDisplayInRect:] to invalidate the rectangle(s) that need to be updated and then wait until the next refresh. What is true, that -[NSView setNeedsDisplayInRect:] are often called multiple times for the same rectangles, but I don't think it matters. I run my app with the Shark tool and drag the mouse to resize an object, to and fro, for few seconds, then check the sample. It always shows that 20-30% of time is taken by the NSRectFill function, which is called only once to simply draw the background of the view with solid white! This is ridiculous. I tried to put an NSLog near the NSRectFill call to check if it is called extra times, but it seems that it is being called exactly one time per single mouse drag message. When I comment out the call to NSRectFill, then the refresh becomes noticeably smoother, and the Shark gives leadership to other bottlenecks, in my case the NSBezierPath stroke and fill messages, for the objects drawn in the view. Any ideas? On Sat, Dec 20, 2008 at 1:45 AM, Peter Ammon wrote: On Dec 19, 2008, at 7:37 AM, Oleg Krupnov wrote: I'm developing a custom view and noticed that drawRect is becoming increasingly slow. The Shark has pointed out that the bottleneck is the NSRectFill function (that calls CGContextFillRect under the hood) that I use to draw the background of the view. A common cause of apparently excessive time in graphics related ops is that you are running afoul of coalesced updates by attempting to refresh faster than 60 times a second. See http://developer.apple.com/documentation/Performance/Conceptual/Drawing/Articles/FlushingContent.html . Try disabling coalesced updates in Quartz Debug and see if it speeds up your drawing. If so, ensure your app does not refresh faster than 60 Hz. -Peter ___ 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/devlists%40shadowlab.org This email sent to devli...@shadowlab.org ___ 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: Get notified of fullscreen switch
Hi Eric, thanks for the quick response. "Listening" to the Carbon Event you described did it. The only "disadvantage" is: Now the App depends on Carbon.framework so far it was Cocoa, Quartz, QuartzCore and ScriptingBridge only But, between the lines of your reply I could read that there'll be a pure Cocoa solution in the future. regards, Joachim Am 17.12.2008 um 18:59 schrieb Eric Schlegel: On Dec 17, 2008, at 9:26 AM, Joachim Deelen wrote: Is there a way, that my application (Playwatch), which is an iTunes Controller running in the menu bar, gets notified, when another Application, like DVD-Player, switches to full screen (kiosk) mode? At the moment, the recommended way to do this is to use a Carbon event handler for the kEventAppSystemUIModeChanged Carbon event. -eric ___ 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: Optimizing NSRectFill
Le 20 déc. 08 à 15:33, Jean-Daniel Dupas a écrit : Sorry for the blank previous mail. Try to call NSFillRect with the rect pased as parameter in drawRect: and before applying the scaling method. As the rect parameter contains the invalid rect in screen coordinates, you don't have to transform it before filling the rect with white. To be exact, the rect parameter is in screen coordinates. So you have to convert it to your view coordinates before drawing. And so, you have to apply to it the reverse of your "view -> screen" transform (that you apply to the context). And so, this is what append: - You apply scaling to the context. - You apply reverse scalling to the rect. - You call Fill Rect =>The system applies the context's transformation to your rect (and revert it back to screen coord) and fills it. That's why I suggest you can fill it directly before applying the transform to the context. But for other drawing, you should use the transformed rect to compute what should be refreshed. Le 20 déc. 08 à 15:22, Oleg Krupnov a écrit : Here is how I arrived at the conclusion that NSRectFill is the bottleneck. (I cannot show the code because it's spread over objects). The slowness of redraw is only noticeable when I drag the mouse, e.g. to resize an object in the custom view. I see that update of the resized object is always late after the actual position of the mouse pointer, and the latency is sometimes pretty great to not be excused. Especially when the size of the rectangle to be updated is large. My custom view supports zooming, so I call NSRectFill after setting an NSAffineTransform. Larger zooms, as I said, seem to cause greater latency. Sometimes I also use clipping ([NSBezierPath addClip]) before calling NSRectFill. I never call -[NSView displayIfNeeded] or use other ways of forcing the view to update itself. I always rely on -[NSView setNeedsDisplayInRect:] to invalidate the rectangle(s) that need to be updated and then wait until the next refresh. What is true, that -[NSView setNeedsDisplayInRect:] are often called multiple times for the same rectangles, but I don't think it matters. I run my app with the Shark tool and drag the mouse to resize an object, to and fro, for few seconds, then check the sample. It always shows that 20-30% of time is taken by the NSRectFill function, which is called only once to simply draw the background of the view with solid white! This is ridiculous. I tried to put an NSLog near the NSRectFill call to check if it is called extra times, but it seems that it is being called exactly one time per single mouse drag message. When I comment out the call to NSRectFill, then the refresh becomes noticeably smoother, and the Shark gives leadership to other bottlenecks, in my case the NSBezierPath stroke and fill messages, for the objects drawn in the view. Any ideas? On Sat, Dec 20, 2008 at 1:45 AM, Peter Ammon wrote: On Dec 19, 2008, at 7:37 AM, Oleg Krupnov wrote: I'm developing a custom view and noticed that drawRect is becoming increasingly slow. The Shark has pointed out that the bottleneck is the NSRectFill function (that calls CGContextFillRect under the hood) that I use to draw the background of the view. A common cause of apparently excessive time in graphics related ops is that you are running afoul of coalesced updates by attempting to refresh faster than 60 times a second. See http://developer.apple.com/documentation/Performance/Conceptual/Drawing/Articles/FlushingContent.html . Try disabling coalesced updates in Quartz Debug and see if it speeds up your drawing. If so, ensure your app does not refresh faster than 60 Hz. -Peter ___ 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/devlists%40shadowlab.org This email sent to devli...@shadowlab.org ___ 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/devlists%40shadowlab.org This email sent to devli...@shadowlab.org ___ 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
Trackpad multi touch events in Mac OSX
Hi, is there a public API to catch the new trackpad multi touch events in Mac OSX? 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
MathPaper (Chapter 10) fails
MathPaper project chapter 10 in Oreilly¹s ³Building Cocoa Applications² fails with the following error: ³2008-12-20 11:23:59.664 MathPaper[517] *** -[NSCFDictionary setObject:forKey:]: attempt to insert nil value² Note that I am using Xcode 2.4.1. I also have the evaluator copied under MathPaper in targets. I have searched the archives and found others have had this problem but I did not find a resolution. Evaluator fails to launch? Code is as follows: - (void)windowDidLoad { NSString *path=0; [super windowDidLoad]; [[self window] makeFirstResponder:theText]; path = [[NSBundle mainBundle] pathForAuxiliaryExecutable:@"Evaluator"]; NSLog(@"path set"); toPipe = [NSPipe pipe]; fromPipe = [NSPipe pipe]; toEvaluator = [toPipe fileHandleForWriting]; fromEvaluator = [fromPipe fileHandleForReading]; NSLog(@"pipe set"); evaluator = [[NSTask alloc] init]; [evaluator setLaunchPath:path]; [evaluator setStandardOutput:fromPipe]; [evaluator setStandardInput:toPipe]; [evaluator launch]; NSLog(@"Evaluator launched"); [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(gotData:) name:NSFileHandleReadCompletionNotification object:fromEvaluator]; [fromEvaluator readInBackgroundAndNotify]; } ___ 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 use animation for CALayer frame.size attribute?
Hi everyone.I am trying to create some animation when to change the size of a CALayer object. My code looks like this: CABasicAnimation * _animation =[CABasicAnimation animation]. [_animation setKeyPath:@"frame.size"]; NSSize _size; *_size.**width** = 400**;* *_size.**height** = 300**;* *_animation.fromValue = [NSValue valueWithSize:_size];* *_size.**width** = 200**;* *_size.**height** = 150**;* *_animation.toValue = [**NSValue** **valueWithSize**:_size];* *[_layer **addAnimation**:_animation* * **forKey**:_animationKey];* However, the above code doesn't work at all. Can anyone tell me what is wrong with that? Or did I miss anything? Thank you very much for any help or guidance. Good luck. -- Best regards. ___ 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: Using runtime functions to match up object types safely when setting properties
On Sat, Dec 20, 2008 at 5:16 AM, Graham Cox wrote: > KVV works pretty well for this - it also solves another related situation > where I can usefully convert objects to other types in some cases - but what > I still haven't quite worked out yet is how to *prevent* the situation > arising in the first place, in other words, given a list of methods, and an > object class, how to filter out those methods/properties from a list that > can't accept the object. There is no way to prevent the situation in the first place using standard techniques. All that static typing information gets thrown away when you compile. At runtime all that survives is the knowledge that your method takes an object pointer of some kind. You could build a table, either manually or perhaps with the help of some sort of crazy macro. But there is absolutely no way to get the NSColor out of -(void)setColor:(NSColor*)c at runtime because that info simply isn't there. 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: Question Regarding the Memory Address of Objects
On Sat, Dec 20, 2008 at 7:00 AM, Clark S. Cox III wrote: > The objective-c garbage collector does not move objects, so that is not an > issue with using raw pointers. But note that storing a pointer value in a string like this is still problematic under garbage collection. It will not act like a strong reference, so the object may be destroyed while still being "referenced" by the string. But it will not act like a zeroing weak reference either, so you'll still be able to get the pointer even after it's been destroyed, which will (probably) lead to a crash. An NSMapTable can be configured to give either reasonable behavior (strong or zeroing weak reference) so use that instead. 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: Optimizing NSRectFill
On Sat, Dec 20, 2008 at 9:22 AM, Oleg Krupnov wrote: > Here is how I arrived at the conclusion that NSRectFill is the > bottleneck. (I cannot show the code because it's spread over objects). > > The slowness of redraw is only noticeable when I drag the mouse, e.g. > to resize an object in the custom view. I see that update of the > resized object is always late after the actual position of the mouse > pointer, and the latency is sometimes pretty great to not be excused. > Especially when the size of the rectangle to be updated is large. When doing things like this you always need to coalesce events before drawing. If you're triggering a redraw for every event then you always leave yourself open to problems. The moment that your events come in faster than your redraws can occur, you lose. This doesn't necessarily only happen when your code is really slow. Maybe you find a user on a really slow computer. Maybe the computer starts to swap. Maybe the computer is running 300 CPU intensive processes simultaneously. Maybe the mouse is sending events at 120Hz and the screen is only refreshing at 60Hz. A simple way to do this is to avoid calling setNeedsDisplay: (or its friends) directly from your event handler. Instead start a timer with some suitably small interval, and set a flag. If the flag is already set, don't start the timer, it's already been started. When the timer fires, invalidate the view and clear the flag. Once you've done this, if it's still too slow then it will manifest as simply being unsmooth, but it will still follow your mouse movements in realtime, which is a substantial improvement. If it's still too slow at that point then you can see what else might be going on and try to fix it from a better position. 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
toolbar to view gradient displaying correctly only sometimes?
i have a window with a toolbar, and instead of having a sharp separation between the toolbar and window, i've created a gradient from toolbar color to window color (which is simply a custom view placed over the window). this gradient looks correct on my iMac 24", and correct on other MacBooks. however, i'm now on my dad's 20" iMac and the gradient isn't smooth at all. it is clearly a gradient band that is separating the toolbar from the window's view area, instead of a proper gradient. i'm assuming this is a problem with the screen/color on my dad's 20" iMac (Alu 2007), but i can't be sure. it would be great for others to look at this attached image and post back whether the gradient is proper, or if it is clearly a band because the gradient's colors are darker than they should be. also, eventhough this isn't a cocoa dev question, is there a reason why my dad's 20 alu iMac 2007 would be displaying this gradient improperly? <>___ 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: Optimizing NSRectFill
On Dec 20, 2008, at 9:18 AM, Michael Ash wrote: When doing things like this you always need to coalesce events before drawing. If you're triggering a redraw for every event then you always leave yourself open to problems. The moment that your events come in faster than your redraws can occur, you lose. This doesn't necessarily only happen when your code is really slow. Maybe you find a user on a really slow computer. Maybe the computer starts to swap. Maybe the computer is running 300 CPU intensive processes simultaneously. Maybe the mouse is sending events at 120Hz and the screen is only refreshing at 60Hz. And... maybe the test case involves grabbing something w/the mouse and then rapidly waving the object back and forth over the view to "quickly" grab some data to sample, thus making the original problem seem much, much, worse. (No -- I'm not saying the problem doesn't exist... just that we developers tend toward spastic monkey behavior when optimizing something that a real user would perform with directness.) b.bum ___ 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: Question Regarding the Memory Address of Objects
> An NSMapTable can be configured to give either reasonable behavior > (strong or zeroing weak reference) so use that instead. Or, in this special case, simply make sure that the dictionary is only used while the controller is live--especially easy if the dictionary is a private field of the controller... I forget the details of the original message, and whether the code has to dynamically adapt to different sets of outlets. If not, then consider: enum { kButton1 = 0, kButton2, kText1, ..., kNumOfControls}; id controls[kNumOfControls]; controls[kButton1] = button1; ... For (int i = 0; i < kNumOfControls; ++i) [controls[i] doSomething: ...]; -- Scott Ribe scott_r...@killerbytes.com http://www.killerbytes.com/ (303) 722-0567 voice ___ 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
selectionShouldChangeInTableView called twice
Hi, I'm using a master/detail view in my application. If the user select another row in the master table and the detail has been modified, I want to present an alert to save, cancel or return to detail. I'm not using binding here, only datasource and delegate methods. So in - selectionShouldChangeInTableView: I return YES if the user saved or cancelled and NO if he choose the third option. Problem is that selectionShouldChangeInTableView is called twice when returning NO. Having googled it, I found a couple of matches on this list and no replies... To make sure this is a bug, I made a test project available here and will radar it if it has no workaround: http://idisk.mac.com/miyano/Public/TestRowChanges.zip Now, since I can't rely on -selectionShouldChangeInTableView:, how do you guys handle this? Thanks, Andre Masse ___ 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
NSBezierPath
Hi, does anyone knows how can I use the NSBezierPath function to create a circle? thanx. ___ 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: NSBezierPath
On Dec 20, 2008, at 11:35 AM, Amr Nashaat wrote: does anyone knows how can I use the NSBezierPath function NSBezierPath is not a "function", but anyway... to create a circle? + (NSBezierPath *)bezierPathWithOvalInRect:(NSRect)aRect where aRect describes a square. ___ 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: Optimizing NSRectFill
On Sat, Dec 20, 2008 at 12:18 PM, Michael Ash wrote: > A simple way to do this is to avoid calling setNeedsDisplay: (or its > friends) directly from your event handler. Instead start a timer with > some suitably small interval, and set a flag. If the flag is already > set, don't start the timer, it's already been started. When the timer > fires, invalidate the view and clear the flag. Alright, perhaps I don't completely understand how the drawing model works at a low enough level, but why would this be helpful? Doesn't AppKit just coalesce updates received by -setNeedsDisplayInRect: until Quartz has finished pushing pixels? So if you are accumulating dirty rects in your event handler, your drawing should still be limited to min(as fast as possible, 60hz). Or am I thinking of the Quartz GL pipeline? --Kyle Sluder ___ 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: toolbar to view gradient displaying correctly only sometimes?
It certainly doesn't blend the toolbar to the toolbar to the window, but I don't see anything else wrong with the gradient. Why do you want to do this anyway? Note that the gradient will always look silly on Tiger. On 20 Dec 2008, at 17:39:16, Chunk 1978 wrote: i have a window with a toolbar, and instead of having a sharp separation between the toolbar and window, i've created a gradient from toolbar color to window color (which is simply a custom view placed over the window). this gradient looks correct on my iMac 24", and correct on other MacBooks. however, i'm now on my dad's 20" iMac and the gradient isn't smooth at all. it is clearly a gradient band that is separating the toolbar from the window's view area, instead of a proper gradient. i'm assuming this is a problem with the screen/color on my dad's 20" iMac (Alu 2007), but i can't be sure. it would be great for others to look at this attached image and post back whether the gradient is proper, or if it is clearly a band because the gradient's colors are darker than they should be. also, eventhough this isn't a cocoa dev question, is there a reason why my dad's 20 alu iMac 2007 would be displaying this gradient improperly? ___ 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/importedfromspace%40googlemail.com This email sent to importedfromsp...@googlemail.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
Find Panel Stopped Working (maybe)
I have the "Uses Find Panel" checked for the only NSTextView in a window, but it does not use a Find panel. I think it used to use the Find Panel before (but I am not sure). Is there something more that is needed besides checking that box? Some other possibilities: 1. I noticed the items in the Find menu were not connected to any actions. I tried connecting them all to performFindPanelAction: (I could not find any other options that make sense), but that did not make it work. 2. The NSTextView is in an NSScrollField which is in an NSSplitView. I used to used a standard NSTextView but recently subclassed it for some extra features. The subclass does very little. I tried commenting out all its methods (so it does nothing more than an NSTextView) and that did not make the Find Panel work either. --- John Nairn GEDitCOM - Genealogy Software for the Macintosh http://www.geditcom.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: MathPaper (Chapter 10) fails
On Sat, Dec 20, 2008 at 11:28 AM, Richard S. French wrote: > Note that I am using Xcode 2.4.1. I also have the evaluator copied under > MathPaper in targets. Where is it being copied to? (It is under a "Copy Files" phase, correct?). Instead of just printing "path set", try logging the value of path to make sure that -[NSBundle pathForAuxiliaryExecutable:] was actually able to find the path of your Evaluator binary. Or, add breakpoints on objc_exception_throw and -[NSException raise] and examine the value in the debugger. --Kyle Sluder ___ 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: Get notified of fullscreen switch
On Dec 20, 2008, at 6:49 AM, Joachim Deelen wrote: Hi Eric, thanks for the quick response. "Listening" to the Carbon Event you described did it. The only "disadvantage" is: Now the App depends on Carbon.framework so far it was Cocoa, Quartz, QuartzCore and ScriptingBridge only But, between the lines of your reply I could read that there'll be a pure Cocoa solution in the future. The AppKit team is aware of the desire for a Cocoa-only solution here and they have some plans to address it. That's all I can say for now. :) -eric ___ 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: Find Panel Stopped Working (maybe)
On Sat, Dec 20, 2008 at 2:10 PM, John Nairn wrote: > 1. I noticed the items in the Find menu were not connected to any actions. I > tried connecting them all to performFindPanelAction: (I could not find any > other options that make sense), but that did not make it work. Looking at TextEdit's MainMenu.nib, Find, Find Next, Find Previous, and Use Selection for Find are all wired up to First Responder's -performFindPanelAction:. Find is tag 1, Find Next=2, Find Previous=3, and Use Selection=7. Jump to Selection is wired up to First Responder's -centerSelectionInVisibleArea:. Maybe you've wired up your actions to the wrong object? --Kyle Sluder ___ 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 use animation for CALayer frame.size attribute?
I'm hoping that all of the asterisks are just artifacts from a copy/ paste maneuver or something, however, if they are not then you're missing some serious fundamentals. This code will never compile. Let's just assume a copy/paste issue. If you are wanting to animate the size of the frame, use the bounds property instead of frame. http://developer.apple.com/qa/qa2008/qa1620.html -Matt On Dec 20, 2008, at 10:04 AM, Alex.Wang wrote: Hi everyone.I am trying to create some animation when to change the size of a CALayer object. My code looks like this: CABasicAnimation * _animation =[CABasicAnimation animation]. [_animation setKeyPath:@"frame.size"]; NSSize _size; *_size.**width** = 400**;* *_size.**height** = 300**;* *_animation.fromValue = [NSValue valueWithSize:_size];* *_size.**width** = 200**;* *_size.**height** = 150**;* *_animation.toValue = [**NSValue** **valueWithSize**:_size];* *[_layer **addAnimation**:_animation* * **forKey**:_animationKey];* However, the above code doesn't work at all. Can anyone tell me what is wrong with that? Or did I miss anything? Thank you very much for any help or guidance. Good luck. -- Best regards. ___ ___ 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: Find Panel Stopped Working (maybe)
Thanks Kyle. That did solve it. I am guessing it never worked before and that my original nib file was created before 10.3 and thus did not use the required performFindPanelAction tags. I did wire them to the correct actions, by I assume NSTextView validated according to those tags and since they were wrong, the menu commands were always disabled. On Dec 20, 2008, at 11:18 AM, Kyle Sluder wrote: On Sat, Dec 20, 2008 at 2:10 PM, John Nairn wrote: 1. I noticed the items in the Find menu were not connected to any actions. I tried connecting them all to performFindPanelAction: (I could not find any other options that make sense), but that did not make it work. Looking at TextEdit's MainMenu.nib, Find, Find Next, Find Previous, and Use Selection for Find are all wired up to First Responder's -performFindPanelAction:. Find is tag 1, Find Next=2, Find Previous=3, and Use Selection=7. Jump to Selection is wired up to First Responder's -centerSelectionInVisibleArea:. Maybe you've wired up your actions to the wrong object? --Kyle Sluder --- John Nairn GEDitCOM - Genealogy Software for the Macintosh http://www.geditcom.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: Trackpad multi touch events in Mac OSX
On 20-Dec-08, at 10:56 AM, Andreas Eriksson wrote: Hi, is there a public API to catch the new trackpad multi touch events in Mac OSX? No. ___ 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: NSBezierPath
On Sat, Dec 20, 2008 at 1:35 PM, Amr Nashaat wrote: > Hi, > > does anyone knows how can I use the NSBezierPath function to create a > circle? Have you considered searching the internet? If I take your question and put it verbatim into Google, the very first hit that comes back has sample code that exactly answers your question 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: Optimizing NSRectFill
On Sat, Dec 20, 2008 at 1:51 PM, Kyle Sluder wrote: > On Sat, Dec 20, 2008 at 12:18 PM, Michael Ash wrote: >> A simple way to do this is to avoid calling setNeedsDisplay: (or its >> friends) directly from your event handler. Instead start a timer with >> some suitably small interval, and set a flag. If the flag is already >> set, don't start the timer, it's already been started. When the timer >> fires, invalidate the view and clear the flag. > > Alright, perhaps I don't completely understand how the drawing model > works at a low enough level, but why would this be helpful? Doesn't > AppKit just coalesce updates received by -setNeedsDisplayInRect: until > Quartz has finished pushing pixels? So if you are accumulating dirty > rects in your event handler, your drawing should still be limited to > min(as fast as possible, 60hz). > > Or am I thinking of the Quartz GL pipeline? My understanding is that everything is sychronous. So if you call setNeedsDisplay: in your event handler, then the sequence will always look like this: event handler mark view invalid check for invalidated views redraw invalidated view flush results to screen event handler mark view invalid check for invalidated views redraw invalidated view flush results to screen And so forth. I could be wrong about this, and if anyone knows better please pipe up! 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: Sorting an NSMutableArray
See -sortUsingFunction:context: in NSMutableArray’s documentation. As Ricky Sharp has already mentioned, there’s also -sortUsingSelector:, however if you’re comparing partly with external data you might like having the void * context provided by this method. Sincerely, Rob On 20-Dec-08, at 7:15 AM, Jacob Rhoden wrote: How do you sort an NSMutableArray, when the difference between the two objects is determined by information not contained completely within the objects themselves. ie in Java you can implement a Comparator that takes two objects to compare then. Is this similar in Cocoa? ie in this case I need to apply a mathematical algorithm using information from each object to determine which one is greater than the other. Thanks! Jacob http://jacobrhoden.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/rix.rob%40gmail.com This email sent to rix@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: Optimizing NSRectFill
Le 20 déc. 08 à 21:14, Michael Ash a écrit : On Sat, Dec 20, 2008 at 1:51 PM, Kyle Sluder wrote: On Sat, Dec 20, 2008 at 12:18 PM, Michael Ash wrote: A simple way to do this is to avoid calling setNeedsDisplay: (or its friends) directly from your event handler. Instead start a timer with some suitably small interval, and set a flag. If the flag is already set, don't start the timer, it's already been started. When the timer fires, invalidate the view and clear the flag. Alright, perhaps I don't completely understand how the drawing model works at a low enough level, but why would this be helpful? Doesn't AppKit just coalesce updates received by -setNeedsDisplayInRect: until Quartz has finished pushing pixels? So if you are accumulating dirty rects in your event handler, your drawing should still be limited to min(as fast as possible, 60hz). Or am I thinking of the Quartz GL pipeline? My understanding is that everything is sychronous. So if you call setNeedsDisplay: in your event handler, then the sequence will always look like this: event handler mark view invalid check for invalidated views redraw invalidated view flush results to screen event handler mark view invalid check for invalidated views redraw invalidated view flush results to screen And so forth. I could be wrong about this, and if anyone knows better please pipe up! I did a quick test. I have a 1ms timer which just do -setNeedDisplay: on a small view. And the result is that my timer callback is called 60 times per seconds. If I remove the seetNeedDisplay: call, it is called 1000 times (as expected). So I think that you're right (and that everything is synchronous) but I also think that the 'flush results to screen' blocks until the screen is ready and so limit the number of redraw to the refresh rate of the screen. If this is effectively the case, your timer trick will not be very helpful. ___ 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: Optimizing NSRectFill
Le 20 déc. 08 à 22:47, Jean-Daniel Dupas a écrit : Le 20 déc. 08 à 21:14, Michael Ash a écrit : On Sat, Dec 20, 2008 at 1:51 PM, Kyle Sluder wrote: On Sat, Dec 20, 2008 at 12:18 PM, Michael Ash wrote: A simple way to do this is to avoid calling setNeedsDisplay: (or its friends) directly from your event handler. Instead start a timer with some suitably small interval, and set a flag. If the flag is already set, don't start the timer, it's already been started. When the timer fires, invalidate the view and clear the flag. Alright, perhaps I don't completely understand how the drawing model works at a low enough level, but why would this be helpful? Doesn't AppKit just coalesce updates received by -setNeedsDisplayInRect: until Quartz has finished pushing pixels? So if you are accumulating dirty rects in your event handler, your drawing should still be limited to min(as fast as possible, 60hz). Or am I thinking of the Quartz GL pipeline? My understanding is that everything is sychronous. So if you call setNeedsDisplay: in your event handler, then the sequence will always look like this: event handler mark view invalid check for invalidated views redraw invalidated view flush results to screen event handler mark view invalid check for invalidated views redraw invalidated view flush results to screen And so forth. I could be wrong about this, and if anyone knows better please pipe up! I did a quick test. I have a 1ms timer which just do -setNeedDisplay: on a small view. And the result is that my timer callback is called 60 times per seconds. If I remove the seetNeedDisplay: call, it is called 1000 times (as expected). So I think that you're right (and that everything is synchronous) but I also think that the 'flush results to screen' blocks until the screen is ready and so limit the number of redraw to the refresh rate of the screen. If this is effectively the case, your timer trick will not be very helpful. How, and I found that too: http://developer.apple.com/technotes/tn2005/tn2133.html ___ 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: Text track in QTMovie
Okay, I took your suggestions. It seems that my array of characters is the issue. My ByteCount s and other variables have seemingly correct values, but the array of chars' value does not change from before it gets written to. So, I tried a few more ways and no luck. I tried using a UInt8 *chars = malloc(size) char *chars = malloc(size). But still no luck. I have a feeling that it has to do with how I initialize it. K&R is coming this week, so, that should help me too (thanks for the recommendation!!). Thanks a ton! Joe On Dec 16, 2008, at 1:28 PM, douglas welton wrote: Hi Joe, My suggestions: 1) write a small application that test your routine before you give it someone else to use. given the code you already have doing this should take all of 5 minutes. Once you do this, you can use the debugger and find your boo-boos. I suspect they will be quite obvious. 2) GetMediaSample2 returns an error code. However, the code in your email does not check the returned value. Making an assumption that the function has completed without an error may not be in your term best interest ;^} 3) chars[] is not a C function call. K&R is your friend! regards, douglas On Dec 16, 2008, at 1:40 PM, Joe Turner wrote: Sorry for taking so long. Okay, what I am looking for is the contents of the text track. Like, for a movie, it would be the chapter names and times. The issue is that I am making this for someone who is using AppleScript, and is just using a call method on my method to do this. So, the Debugger will not stop at my breakpoints (I thought it did, even if it is being called by a call method). Anyways, I guess what I am looking for is an error in the code I have created. Like, am I passing something wrong? Am I trying to parse something as a different format than it is? I can create a new project and do this and tell you the debugger contents too though, if needed. I am used to objective-c, and some of these C calls can confuse me sometimes. Like, is chars[] the same thing as a UInt8? Thanks for your help, Joe On Dec 14, 2008, at 8:54 PM, douglas welton wrote: when you say it won't show you the "track names" do you mean: a) your NSLog() function is failing and nothing is printed b) NSLog() prints something, but the value of string appears to be either nil or empty (which one?) c) you really want the name of the track (i.e., the thing displayed in the QT Player) and not the text in each sample. If this is the case then we have to do something entirely different ;^} d) all of the function calls succeed and when examined in the debugger you can see the values for size and chars[] are valid but your NSString cannot be properly constructed. Can you clarify? BTW, what values are you seeing in the debugger? On Dec 14, 2008, at 8:33 PM, Joe Turner wrote: Okay, so I did what you said, but yet, it still won't show me the track names. Here is my code: Media media = [movieView movie] tracksOfMediaType:QTMediaTypeText] objectAtIndex:0] media] quickTimeMedia]; TimeValue64 timeValue = 0; TimeValue64 duration = 0; GetMediaNextInterestingDecodeTime(media, nextTimeMediaSample + nextTimeEdgeOK, timeValue, fixed1, &timeValue, &duration); ByteCount size; GetMediaSample2(media, NULL, 0, &size, timeValue, NULL, NULL, NULL, nil, nil, 1, NULL, NULL); char chars[size]; GetMediaSample2(media, &chars, size, NULL, timeValue, NULL, NULL, NULL, nil, nil, 1, NULL, NULL); NSString *string = [[NSString alloc] initWithBytes:chars length:size encoding:NSUTF8StringEncoding]; NSLog(@"String: %@", string); Thanks, Joe On Dec 14, 2008, at 7:03 PM, douglas welton wrote: Hi Joe, Since you didn't define "easy" or tell me what you'd tried, then I'll have to make some assumptions about what you know. I will assume that you have read the documentation on QT media samples. The basic steps: Get the text track. Get the track media. loop thru the media samples using a function like GetMediaNextInterestingDecodeTime() with the parameters of your choice Use GetMediaSample2() to get the data/length associated with the text sample. Create an NSString with the bytes/length returned in the previous call regards, douglas On Dec 14, 2008, at 7:26 PM, Joe Turner wrote: I have a QTMovie (that is valid), and it has a text track. I am wondering if there is any easy way to get the contents of the text track into an NSString. Thanks, Joe ___ 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.c
Re: toolbar to view gradient displaying correctly only sometimes?
On 21 Dec 2008, at 4:39 am, Chunk 1978 wrote: is there a reason why my dad's 20 alu iMac 2007 would be displaying this gradient improperly? Many Macs have 6-bit LCD displays, making them incapable of displaying 32-bit colour, which requires 8-bit pixels. Could that be it? You might also find that settings such as the screen's gamma can strongly affect the appearance of gradients, etc. Try examining the settings in the Display System Prefs. In fact if your UI is sensitive to such things, it's probably best to try something else. --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: Using runtime functions to match up object types safely when setting properties
On 21 Dec 2008, at 4:07 am, Michael Ash wrote: You could build a table, either manually or perhaps with the help of some sort of crazy macro. But there is absolutely no way to get the NSColor out of -(void)setColor:(NSColor*)c at runtime because that info simply isn't there. Yep, I've come to understand that. It looks as if I'll have to extend the scheme where my objects publish the properties that are exposed in the UI to also include acceptable type information, so the UI has something to go on when disabling improper combinations. A bit of a pain but not all that unreasonable. thanks everyone for helping out, cheers, 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: selectionShouldChangeInTableView called twice
On 21 Dec 2008, at 5:23 am, Andre Masse wrote: I'm using a master/detail view in my application. If the user select another row in the master table and the detail has been modified, I want to present an alert to save, cancel or return to detail. Just my 2¢ worth, but this sounds like a horrible UI. If I get interrupted by an alert every time I change a table selection, I'm going to get pretty irritated by that quite quickly. Normally table selections changes are considered "cheap", and the user shouldn't be punished for browsing. Instead why not just keep a change flag for each modified object, then at some suitable time when the user is moving to a task that needs to use the modified data or else revert to the earlier state, check the flags and only present the alert once. This is how Mail's preferences settings work for example - I can change lots of different settings but only when I close the window am I prompted to save any changes I made. It's much less intrusive. --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: Newbie Question: implementing a stack
On Dec 20, 2008, at Dec 20:12:08 AM, Graham Cox wrote: On 20 Dec 2008, at 4:52 pm, Graham Cox wrote: On 20 Dec 2008, at 3:15 pm, Steve Wetzel wrote: Regarding memory management - does it make more sense to copy the object to be pushed from within the Stack object rather then copying it externally before the push call? I am thinking that it does because then that object is encapsulated which is how a stack should really work. If I do this I realize I will need to implement a copy method within any object that I want to place on the stack if it does not already have one. My own view is that the stack object shouldn't copy the object. Of course, a very easy, and generally useful solution, is to provide two methods: - (void)push:(id) obj; - (void)pushCopy:(id) obj; G. I do see your point Graham but what I am trying to understand is how to work with the stack if I don't copy the object to put on it. If I simply push the pointer on the stack, it seems that I have to make a lot of objects in the code that handles the stack object. If I have an class MyObject I wish to push on the stack: MyObject *myObj1 = [[MyObject alloc] init]; MyObject *myObj2 = [[MyObject alloc] init]; ... MyObject *myObj10 = [[MyObject alloc] init]; [stack push:myObj1]; [stack push:myObj2]; ... [stack push:myObj10]; Each time I want to push a MyObject onto the stack I need to create a new MyObject. If I copy I can do: MyObject *myObj = [[MyObject alloc] init]; [stack push:myObj]; [stack push:myObj]; ... I guess can simply assign the pointer, but if I do, it seems to me I will need an NSMutableArray to hold myObj1... myObj10 (or more). If I do that, what benefit is the stack? 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
Copying Managed Objects from App to Doc MOContext
My app maintains in its managed object context an array of, say, Potato objects. The potatoes in this central managed object context come and go occasionally -- someone might throw in a new one, or eat one. An archived potato is low in calories, consisting of a half dozen numbers or short strings. My persistent documents can also contain several potatoes. To set one, user clicks a popup menu in the document window. The popup is populated by the potatoes currently available in the central managed object context. Because the potatoes in this popup are inserted into the central managed object context, however, I cannot simply "set" one of them into my document when the user makes their seledtion. I implement a custom setter which inserts a ^new^ potato into the document's managed object context, and copies to it all of the attributes from the selected potato. Looks OK to me, but having never seen anything like this, I was wondering if I'm seeing OK today. Thank you, Jerry Krinock Here are a couple of (not yet fully tested) methods which can be implemented in a category or subclass of NSManagedObject to help with the all-attributes/value copying: .h * /*! @briefA dictionary containing all attribute keys of the receiver for which current values are not nil, and their values. @details Does not give relationships. The output returned is mutable as a convenience because, in some applications, key/value pairs will be immediately added or removed. Tip: If you want to copy both attribues and properties, use -[NSKeyValueCodingProtocol dictionaryWithValuesForKeys:]. */ - (NSMutableDictionary*)attributesDictionary ; /*! @briefSets the receiver's attributes from a dictionary @details All keys in 'attributes' are attempted to be set using setValue:forKey:. Thus, setValue:forUndefinedKey: will be invoked (and possibly an exception raised) if 'attributes' contains keys for which the receiver is not KVC compliant. attributes The dictionary of attributes to be set. */ - (void)setAttributes:(NSDictionary*)attributes ; .m * - (NSMutableDictionary*)attributesDictionary { NSEntityDescription* entity = [self entity] ; NSDictionary* attributes = [entity attributesByName] ; /* The following one-liner will almost work: return [self dictionaryWithValuesForKeys:attributes] ; Unfortunately, instead of omitting pairs for which the values are nil, it inserts keys with values of NSNull. So, I use my own implementation: */ NSMutableDictionary* attributesDic = [[NSMutableDictionary alloc] init] ; for (id attributeName in attributes) { id value = [self valueForKey:attributeName] ; if (value) { [attributesDic setValue:value forKey:attributeName] ; } } return [attributesDic autorelease] ; } - (void)setAttributes:(NSDictionary*)attributes { for (id attributeName in attributes) { [self setValue:[attributes valueForKey:attributeName] forKey:attributeName] ; } } ___ 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: selectionShouldChangeInTableView called twice
I'm using a master/detail view in my application. If the user select another row in the master table and the detail has been modified, I want to present an alert to save, cancel or return to detail. Just my 2¢ worth, but this sounds like a horrible UI. If I get interrupted by an alert every time I change a table selection, I'm going to get pretty irritated by that quite quickly. Normally table selections changes are considered "cheap", and the user shouldn't be punished for browsing. Instead why not just keep a change flag for each modified object, then at some suitable time when the user is moving to a task that needs to use the modified data or else revert to the earlier state, check the flags and only present the alert once. This is how Mail's preferences settings work for example - I can change lots of different settings but only when I close the window am I prompted to save any changes I made. It's much less intrusive. Not to be picky, but Mail’s accounts pane actually works the way he describes. If I select an account, uncheck “Include when automatically checking for new mail” and then select a different account, it asks me if I want to save the changes before updating the detail view with the contents of the newly-selected account. So there is precedent, although it is a bit annoying. Rob___ 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: Newbie Question: implementing a stack
On 21 Dec 2008, at 10:52 am, Steve Wetzel wrote: I guess can simply assign the pointer, but if I do, it seems to me I will need an NSMutableArray to hold myObj1... myObj10 (or more). If I do that, what benefit is the stack? I don't really follow your argument. Presumably you decided you need a stack for some reason to do with your application's logic - so I can't answer "what benefit is the stack?" - that's up to you! A stack in general terms doesn't inherently copy items placed on it, there's nothing in the definition of 'stack' that implies a copy. It's just storage, with a LIFO semantic. I don't really see what creating objects has do with it - the stack is to do with organising objects, not creating them. --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: selectionShouldChangeInTableView called twice
On 21 Dec 2008, at 11:03 am, Rob Rix wrote: Not to be picky, but Mail’s accounts pane actually works the way he describes. If I select an account, uncheck “Include when automatically checking for new mail” and then select a different account, it asks me if I want to save the changes before updating the detail view with the contents of the newly-selected account. So there is precedent, although it is a bit annoying. Rob Yeah, maybe that's not the best example. In fact just trying it now it doesn't always even work - changing a minor setting such as time to leave mail on server, it causes the save changes sheet to show, then hitting Cancel doesn't revert the setting! On the other hand buttons in a preferences panel are not quite the same thing as a selection in a table - the user is unlikely to expect (or forgive) a UI that interrupts them constantly on a mere selection change. --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
(no subject)
I had a similar problem and there were serious performance issues with the built-in sorting. I could make it work with sortUsingFunction:context:, but the performance depends significantly on the efficiency of that method (i.e., how much work it takes to interact with that external data). In my case, when used for sorting a column with a few thousand lines, it got very slow. I was able to get more much faster sorting (at least 100x) by not relying on built- in tools. If you are interested, here is the process I used: 1. Building a c++ array of integers with indices to the new sort order 2. Precalculate all crucial sort terms (that depend on external data) for the objects to be sorted. 3. Sort the index array manually (e.g., a shell sort from Numerical Recipes in C, pg 244 (my edition)) 4. Once done, build a new array based on the sorted indices, and free any allocated memory Here is partial code. You would have to fill in the objects array and the method (BOOL)checkObj1:(id)obje1 vsObj2:(id)obj2 simply returns YES if the objects need rearranging (i.e., currently in the wrong order). // sorting objects in array order int *ind=(int *)malloc(([order count]+1)*sizeof(int)); NSMutableArray *objects=[[NSMutableArray alloc] initWithCapacity: [order count]]; for(i=0;i<[order count];i++) { ind[i+1]=i; // fill index i of objects with information needed to sort object at item i in order } int n2,n=[order count]; int lognb2=0,j,m,nn,ii,ij; n2=n>>1; while(n2>0) { lognb2++; n2>>=1; } m=n; for(nn=1;nn<=lognb2;nn++) { m>>=1; for(j=m+1;j<=n;j++) { ii=j-m; ij=ind[j]; while(ii>=1 && [self checkObj1:[objects objectAtIndex:ind[ii]] vsObj2:[objects objectAtIndex:ij]]) { ind[ii+m]=ind[ii]; ii-=m; } ind[ii+m]=ij; } } // build new array from sorted indices in ind[], i.e. index i of new array is index ind[i] from original array It will all depend on how efficient you can make the function in the built-in sorting function. For me, the difference was dramatic. See -sortUsingFunction:context: in NSMutableArrays documentation. As Ricky Sharp has already mentioned, theres also -sortUsingSelector:, however if youre comparing partly with external data you might like having the void * context provided by this method. Sincerely, Rob On 20-Dec-08, at 7:15 AM, Jacob Rhoden wrote: How do you sort an NSMutableArray, when the difference between the two objects is determined by information not contained completely within the objects themselves. ie in Java you can implement a Comparator that takes two objects to compare then. Is this similar in Cocoa? ie in this case I need to apply a mathematical algorithm using information from each object to determine which one is greater than the other. Thanks! Jacob --- John Nairn GEDitCOM - Genealogy Software for the Macintosh http://www.geditcom.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: selectionShouldChangeInTableView called twice
On 2008 Dec, 20, at 10:23, Andre Masse wrote: I'm using a master/detail view in my application. If the user select another row in the master table and the detail has been modified, I want to present an alert to save, cancel or return to detail. Back to the original question, I always thought that the desired behavior in this case would be to simply set the change in the data model without asking. You mentioned "save". Indeed, I would not "save" in the sense of saveDocument:. But like Graham said, a table entry is "cheap" [in user effort] to restore the old value if it was a mistake. And the proper, easy way for the user to restore it would be -- drum roll -- Undo -- cowbell :) ___ 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: Copying Managed Objects from App to Doc MOContext
On Sat, Dec 20, 2008 at 6:58 PM, Jerry Krinock wrote: > My app maintains in its managed object context an array of, say, Potato > objects. The potatoes in this central managed object context come and go > occasionally -- someone might throw in a new one, or eat one. An archived > potato is low in calories, consisting of a half dozen numbers or short > strings. This doesn't make sense... you don't store arrays in managed object contexts. There's a set of Potato managed objects in the context, though. So did you mean that, or are you storing some sort of ArrayOfPotatoes managed object somewhere? > My persistent documents can also contain several potatoes. To set one, user > clicks a popup menu in the document window. The popup is populated by the > potatoes currently available in the central managed object context. So, there's a separate app-wide persistent store, or just a separate MOC? > Looks OK to me, but having never seen anything like this, I was wondering if > I'm seeing OK today. It depends on the semantics you're trying to achieve. If what you really want is to store a reference to the central Potato, then store its UUID. If you want to store a copy of the potato, keep doing what you're doing. --Kyle Sluder ___ 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: Optimizing NSRectFill
On Sat, Dec 20, 2008 at 4:47 PM, Jean-Daniel Dupas wrote: > So I think that you're right (and that everything is synchronous) but I also > think that the 'flush results to screen' blocks until the screen is ready > and so limit the number of redraw to the refresh rate of the screen. > If this is effectively the case, your timer trick will not be very helpful. As long as the timer's time interval is less than the screen refresh interval (and the technote says to simply assume 60Hz and that most drawing doesn't need more than 30Hz, so that's easy enough to assure) then it will work. And even if the timer is more, it will depend on the behavior of the event loop. If the event loop is smart it will process all queued events before running the next timer, in which case the technique will work even for a zero-interval timer, but I don't know if it actually works this way. 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: Newbie Question: implementing a stack
On Sat, Dec 20, 2008 at 6:52 PM, Steve Wetzel wrote: > I do see your point Graham but what I am trying to understand is how to work > with the stack if I don't copy the object to put on it. If I simply push > the pointer on the stack, it seems that I have to make a lot of objects in > the code that handles the stack object. If I have an class MyObject I wish > to push on the stack: > > MyObject *myObj1 = [[MyObject alloc] init]; > MyObject *myObj2 = [[MyObject alloc] init]; > ... > MyObject *myObj10 = [[MyObject alloc] init]; > > > [stack push:myObj1]; > [stack push:myObj2]; > ... > [stack push:myObj10]; > > Each time I want to push a MyObject onto the stack I need to create a new > MyObject. If I copy I can do: > > MyObject *myObj = [[MyObject alloc] init]; > > [stack push:myObj]; > > [stack push:myObj]; > > ... > > > I guess can simply assign the pointer, but if I do, it seems to me I will > need an NSMutableArray to hold myObj1... myObj10 (or more). If I do that, > what benefit is the stack? You're very confused. When you assign something new to myObj, you're only affecting that one pointer. You don't affect anything else that has a reference to the original object. For example: NSString *str = @"hello"; [stack push:str]; str = @"world"; [stack push:str]; Your stack now contains @"hello" and @"world". It does not matter what its copying behavior is, this is *always* true. (Try it with an NSMutableArray and see; NSMutableArray does not copy the objects it receives.) When you write str = @"world" you just put a new address into the str pointer. But the stack isn't holding your str variable. It's simply holding the value that str held originally. So there's no problem. What copying saves you from is stuff like this: NSMutableString *str = [NSMutableString stringWithString:@"hello"]; [stack push:str]; [str setString:@"world"]; [stack push:str]; In this case the stack ends up holding two copies of a single mutable string which contains the text @"world". Here we aren't mutating "str", we're mutating the *object* that it points to. If the stack copied the object then we wouldn't mutate the copy and so the -setString: call wouldn't change its contents. This usually isn't much of a problem. And to the extent that it is, being able to push non-copyable objects or referenced mutable objects onto a stack will generally far outweigh them. Follow Cocoa's lead: with the exception of dictionary keys, Cocoa does not copy objects that are put into collections. 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: Copying Managed Objects from App to Doc MOContext
On 2008 Dec, 20, at 17:55, Kyle Sluder wrote: This doesn't make sense... you don't store arrays in managed object contexts. Whoops. Indeed, that does not make sense. I should have said that there are potatoes inserted into the app's central managed object context. They're not in an array and not related to any other entity; they just hang loose in there, fetched when needed, which is not very often. So, there's a separate app-wide persistent store, or just a separate MOC? Both. The app-wide MOC has its PSC set to the app-wide PSC, which in turn has a persistent store in the Application Support folder. Looks OK to me, but having never seen anything like this, I was wondering if I'm seeing OK today. It depends on the semantics you're trying to achieve. If what you really want is to store a reference to the central Potato, then store its UUID. If you want to store a copy of the potato, keep doing what you're doing. By UUID, I believe you mean [[[self objectID] URIRepresentation] absoluteString]. I'd considered that, but since it's possible that the source potato in the central store might go away, indeed I want a copy. I was thinking that, for portability and robustness, in most cases one would not want a document to reference an object in an app's Application Support. Thank you, Kyle -- I'm starting to see a clearer picture what I'm doing now. ___ 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: NSTimer help
On 18/12/2008, at 2:20 PM, Andrew Merenbach wrote: Is there a reason to use it in the case that one might instead use - isEqual: or, as was discussed in a recent thread, -isEqualToString: (which was stated, if I recall correctly, to be optimized for speed in the case of strings)? Apologies once again for the tangent, but I am rather curious. I am extremely grateful for any insight. Xcode's autocomplete has sometimes popped up with -isEqualTo: for me, which I guess you might not notice if you're unfamiliar with Cocoa. -- Rob Keniger ___ 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: selectionShouldChangeInTableView called twice
On 21 Dec 2008, at 12:26 pm, Jerry Krinock wrote: On 2008 Dec, 20, at 10:23, Andre Masse wrote: I'm using a master/detail view in my application. If the user select another row in the master table and the detail has been modified, I want to present an alert to save, cancel or return to detail. Back to the original question, I always thought that the desired behavior in this case would be to simply set the change in the data model without asking. You mentioned "save". Indeed, I would not "save" in the sense of saveDocument:. But like Graham said, a table entry is "cheap" [in user effort] to restore the old value if it was a mistake. And the proper, easy way for the user to restore it would be -- drum roll -- Undo -- cowbell :) I agree with this. If the UI is part of an inspector-type interface, i.e. modeless, then just make the change but do it undoably. Performing the Undo naturally updates any visible UI that matters (KVO/Bindings makes this trivial). The main case where a Save/Cancel approach makes much sense is in a modal situation, in which case the OK/Cancel buttons already imply the answer - Save on OK, revert on Cancel. Or, if you prefer for a modeless dialog, present an alert on window close, though I dislike this myself - a modeless window might as well use Undo, unless it's editing a very specific aspect of the data model, such as user defaults, where it's not usually appropriate to use Undo. Bear in mind you can create an undo manager at any time. --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: selectionShouldChangeInTableView called twice
Thanks for your replies guys. This application is a front end to a database with a lot of data entries and deals with legal data. There's a lot of validations going on and data integrity is vital. Normally, the user will save or cancel by clicking a button in the detail view and changes will be committed or rolled back to the database. The alert is for handling the cases where the user select another row in the master table after having done some modifications to a record and "forgot" to save or cancel (most document based application display a similar alert when the window is closed without saving). This case is exceptional. As an analogy, let's say the master table is a list of clients. A typical use case for data entry goes like this: 1- search for a client 2- select the "good" one from the list (if a match is found, if not add a new one) 3- make some modifications in the detail view 4- save repeat Suppose the user begin editing a client then decide this is not the record he wanted to modify and simply select another row in the master table. Or, the master table contains the next client he has to modified and after finishing editing the first, he simply select the next. How can I know what to do without asking him what he want? In the first case I should cancel the record and in the second I should save it. Now, suppose the user somehow move the focus from the detail view (by switching application and coming back, accidently clicking in the master view or whatever). This is a third case, he may have not completed its modifications and should be able to continue editing the record. I agree that this is a restrictive approach and I'll think how I could handle all this with Undo. This has a lot of implications on my application design which rely on being in a database transaction for editing, will never be sold as it's an in house application for 3 users (me, my wife and my son) and has been working this way for years using 4th Dimension on a PC... Food for thoughts :-) Thanks, Andre Masse On Dec 20, 2008, at 20:26, Jerry Krinock wrote: On 2008 Dec, 20, at 10:23, Andre Masse wrote: I'm using a master/detail view in my application. If the user select another row in the master table and the detail has been modified, I want to present an alert to save, cancel or return to detail. Back to the original question, I always thought that the desired behavior in this case would be to simply set the change in the data model without asking. You mentioned "save". Indeed, I would not "save" in the sense of saveDocument:. But like Graham said, a table entry is "cheap" [in user effort] to restore the old value if it was a mistake. And the proper, easy way for the user to restore it would be -- drum roll -- Undo -- cowbell :) ___ 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: Copying Managed Objects from App to Doc MOContext
I am doing something very similar to you. I have an application-based library of potatoes, and each document has a copy of some of those potatoes. I did this because the document may be opened on another computer that does not have access to the same library (or as you mention, the library can change over time, but the document should not change unless someone has explicitly changed it.) An added complication in my case is that when one opens the document, I need to compare the document's potatoes to the library's potatoes and give the user the opportunity to update the document, the library, or both if they are not in sync. This means comparing all the potato attributes for each potato in the document against those in the library. This can be very time consuming if it is not optimized well, but it is certainly doable in Core Data. Another set of complications is: What happens if the user changes the application library while a document is open? Will they expect the document to be automatically updated? If so, should the document be updated immediately, or only after saving changes to the application library? I came up with a concept of "live" versus "archived" documents. If a document is new or dirty, then it is live and it updates its potatoes in sync with the persistent store of the application library. If the document is archived (i.e. it has been opened, but not touched), then it ignores changes to the library. But all this should be based on how your users will expect the application to behave. Dave On Dec 20, 2008, at 9:29 PM, Jerry Krinock wrote: On 2008 Dec, 20, at 17:55, Kyle Sluder wrote: This doesn't make sense... you don't store arrays in managed object contexts. Whoops. Indeed, that does not make sense. I should have said that there are potatoes inserted into the app's central managed object context. They're not in an array and not related to any other entity; they just hang loose in there, fetched when needed, which is not very often. So, there's a separate app-wide persistent store, or just a separate MOC? Both. The app-wide MOC has its PSC set to the app-wide PSC, which in turn has a persistent store in the Application Support folder. Looks OK to me, but having never seen anything like this, I was wondering if I'm seeing OK today. It depends on the semantics you're trying to achieve. If what you really want is to store a reference to the central Potato, then store its UUID. If you want to store a copy of the potato, keep doing what you're doing. By UUID, I believe you mean [[[self objectID] URIRepresentation] absoluteString]. I'd considered that, but since it's possible that the source potato in the central store might go away, indeed I want a copy. I was thinking that, for portability and robustness, in most cases one would not want a document to reference an object in an app's Application Support. Thank you, Kyle -- I'm starting to see a clearer picture what I'm doing now. ___ 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/dave.fernandes% 40utoronto.ca This email sent to dave.fernan...@utoronto.ca ___ 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: selectionShouldChangeInTableView called twice
On Dec 20, 2008, at 22:00, Graham Cox wrote: If the UI is part of an inspector-type interface, i.e. modeless, then just make the change but do it undoably. Performing the Undo naturally updates any visible UI that matters (KVO/Bindings makes this trivial). The main case where a Save/Cancel approach makes much sense is in a modal situation, in which case the OK/Cancel buttons already imply the answer - Save on OK, revert on Cancel. Or, if you prefer for a modeless dialog, present an alert on window close, though I dislike this myself - a modeless window might as well use Undo, unless it's editing a very specific aspect of the data model, such as user defaults, where it's not usually appropriate to use Undo. Bear in mind you can create an undo manager at any time. The UI is using a single window (per database relations) with the master table on the left and detail on the right. I've struggle a lot with this as the detail view in the principal table is pretty complex: 25 fields (although many are generated) and 2 table views (to many relationships). In a typical session, the window will be closed at the end of the day. In the present application (built with 4th Dimension) the window contains the list and users must double-clic on a row to edit a record. Since they often need to check the detail view for a couple of rows before making a decision, I thought it would be great to use a master/detail design. This has some side effects though, hence my reason for using the alert... I will think on the implications of using Undo as there's some limit to this design. The first thing I must resolve is Undoing changes hours or days after entries... Using (database row) versions is expansive as there's more than a million rows spread over many database tables. Not counting the legal implications when saving data to the wrong "client". The present design doesn't always prevent this but gives a more immediate feedback to the user, as "annoying" as it may sounds... Thanks for the comments, I will sleep on this :-) Andre Masse ___ 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: Copying Managed Objects from App to Doc MOContext
On Sat, Dec 20, 2008 at 9:29 PM, Jerry Krinock wrote: > Both. The app-wide MOC has its PSC set to the app-wide PSC, which in turn > has a persistent store in the Application Support folder. OK, good, glad I understood you there. > By UUID, I believe you mean [[[self objectID] URIRepresentation] > absoluteString]. Yes. > I'd considered that, but since it's possible that the source potato in the > central store might go away, indeed I want a copy. I was thinking that, for > portability and robustness, in most cases one would not want a document to > reference an object in an app's Application Support. This is a situation you will need to handle anyway when you're dealing with multiple MOCs, since they don't notify each other of changes. If you are cloning your prototypical potatoes simply because you're afraid of them disappearing in your app's PSC, then I recommend you look into Fetched Properties: http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/CoreData/Articles/cdRelationships.html#//apple_ref/doc/uid/TP40001857-SW7 . Again, you need to determine if your app's semantics really do require you to clone your prototypes. In most apps, for example, if you create a new document based on a template and then change the template the document doesn't get changed. If that's the behavior your app needs, then keep doing what you're doing. Otherwise, look into modeling a cross-store relationship. You could perhaps store a "referencedByCount" attribute in your global objects, and ensure that objects don't get deleted unless this attribute is zero. --Kyle Sluder > > Thank you, Kyle -- I'm starting to see a clearer picture what I'm doing now. > > ___ > > 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/kyle.sluder%40gmail.com > > This email sent to kyle.slu...@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: Using runtime functions to match up object types safely when setting properties
On 20 Dec 08, at 02:16, Graham Cox wrote: On 20 Dec 2008, at 8:05 pm, Andrew Farmer wrote: However, I think you've overengineering things here. The standard runtime introspection methods, like [NSObject class] and [NSObject isKindOfClass:], should be more than enough to implement this sort of functionality. You might be right about the overengineering, but -class and - isKindOfClass: can't be used on methods, only on objects you already have. If you have an object that has a property setter, e.g. - (void)setColor:(NSColor*) aColor; and you have a variable selector that can refer to that (but also potentially many other) methods, and an object that might, or might not, be an NSColor*, how do you make sure you don't end up sending that method a string? Ah... I probably should have explained further. What I was thinking of was a "try first and ask forgiveness" approach - have the calling code attempt to set the property unconditionally, and have the setter throw an exception if the object it's passed is in fact of the wrong type. This isn't any help if you need to *determine* what the desired type is, but it's fine if all you need to be able to do is throw an error when the wrong type of object is passed. ___ 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