Re: I need a milder application badge (solution)
I have cause to display something like an application badge on the docktile of my app, but [the regular one won't do] ... Solution (I think ...): I ended up finding a basically sane way to do this -- just one method, and I did not have to subclass NSView -- but with a large hack for one feature: I was using a pre-existing image for the docktile. That was what I wanted to put the badge on. I created an offscreen window, added an NSImageView the same size as my image to its view hierarchy, then added an instance of NSText as a subview thereof, at an appropriate location. By loading my image into the image view and then drawing the text with a suitable background color, I was able to get a decent badge. Before doing the drawing, I saved the graphics context and set up a new one with the view, and locked focus on the view; I unlocked and restored later. That setup allowed me to use NSBitmapImageRep:initWithFocusedViewRect: to grab the bits as drawn. I loaded the bitmap into a new instance of NSImage, which I could then assign to my docktile. Now the hack: My original image had some transparent areas, and I could not figure out a reasonable technique for capturing the bitmap drawn by the above procedure without also getting the bits for whatever background lay *behind* the transparent areas of my original image. I don't do a lot of graphics work, so if I am overlooking something obvious I will be very grateful if someone will tell me. My hack took advantage of the fact that my badged image did not have any of a certain color. I ended up setting the window background color to that color, then going through the captured bitmap one pixel at a time, changing all pixels that were approximately that color to transparent. (Actually, I had to make a whole new bitmap and copy or make-transparent; the captured bitmap did not have an alpha plane.) That did work, but it is not a very graceful technique or a very general one. -- Jay Reynolds Freeman - jay_reynolds_free...@mac.com http://web.mac.com/jay_reynolds_freeman (personal web site) ___ 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: I need a milder application badge (solution)
On Jul 24, 2009, at 11:17 PM, Jay Reynolds Freeman jay_reynolds_free...@mac.com wrote: I ended up finding a basically sane way to do this -- just one method, and I did not have to subclass NSView -- but with a large hack for one feature: Subclassing NSView is not a big deal. Just override -drawRect, draw the image you want, and draw the badge on top of it. You've basically tried to reimplement the Quartz compositor. :) --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: I need a milder application badge (solution)
On 25/07/2009, at 4:34 PM, Kyle Sluder wrote: I ended up finding a basically sane way to do this -- just one method, and I did not have to subclass NSView -- but with a large hack for one feature: Subclassing NSView is not a big deal. Just override -drawRect, draw the image you want, and draw the badge on top of it. You've basically tried to reimplement the Quartz compositor. :) Yep. As usual with Cocoa, if something seems really hard and complicated to do, you're probably doing it wrong. This is especially true if you are relatively new to Cocoa development. Don't fight the framework! -- 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: I need a milder application badge (solution)
Well, mea culpa, I have not been speaking clearly; what I want to badge is not the dock tile but the dock icon, and I cannot find a way to get at the view for that, so as to install a special class: The interface seems to be through NSApp:applicationIconImage and NSAPP:setApplicationIconImage: So there I am, back messing with bit maps to modify an image. I would welcome a better way. -- Jay Reynolds Freeman - jay_reynolds_free...@mac.com http://web.mac.com/jay_reynolds_freeman (personal web site) On Jul 25, 2009, at 12:30 AM, Rob Keniger wrote: On 25/07/2009, at 4:34 PM, Kyle Sluder wrote: I ended up finding a basically sane way to do this -- just one method, and I did not have to subclass NSView -- but with a large hack for one feature: Subclassing NSView is not a big deal. Just override -drawRect, draw the image you want, and draw the badge on top of it. You've basically tried to reimplement the Quartz compositor. :) Yep. As usual with Cocoa, if something seems really hard and complicated to do, you're probably doing it wrong. This is especially true if you are relatively new to Cocoa development. Don't fight the framework! -- 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/jay_reynolds_freeman%40mac.com This email sent to jay_reynolds_free...@mac.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: NSTableView - populating from C procedure
Am 23.07.2009 um 08:55 schrieb Marco S Hyman: On Jul 22, 2009, at 11:38 PM, Graham Cox wrote: My warning was of a very general nature, and may not apply to your app. But every time you declare buffer space as a stack array, you should mentally consider whether a buffer exploit might be possible there. It was a good warning. Since the author can rarely guarantee that some data field will not be filled from an untrusted source *forever* it is always best to check for and not allow overflow. Why is everyone so fixated on security exploits? You could be causing bugs! E.g. in this case, if the C code assumes a different size for the buffer than the ObjC method calling it (and you're hard-coding the array size instead of using a symbolic constant shared by the two), you may be writing off the end of the array. If you're lucky, you're on 64 bit and overwriting the canary, making your app crash. If you're unlucky, there's a function pointer on the stack that you overwrite with data that is equal to ... oh, I don't know ... the address of a function that deletes the Documents folder's contents, and suddenly the user has lost data. In most cases, though, you'll just be slowly and incrementally corrupting some memory in your app, and half an hour later when that memory is next used, your app will unexplainably crash. Graham Cox wrote: If it checks the buffer size and the string size, it should be OK. Not all dialects of C have historically supported sizeof() for stack- based buffers but I think all modern ones do. I don't think you can use sizeof() on a pointer passed as a parameter, though. That only works on variables in the current scope. That pointer could point at anything, so the compiler has no idea whether it points at the stack or the heap. Even if it generated specialized code for the stack case, what code would it generate for the heap case? sizeof() is independent from malloc(), NewPtr() and all the other allocator schemes the OS knows, sizeof() wouldn't know which one to use. Heck, ANSI malloc() doesn't even have a standard way of determining a block's size. Cheers, -- Uli Kusterer The Witnesses of TeachText are everywhere... http://www.zathras.de ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Challenge: Block Main Thread while Work is done, with Timeout
Am 25.07.2009 um 03:27 schrieb Graham Cox: Display a modal progress window which tells the user's what's going on, show an indeterminate progress bar and include a Stop button. The worker code can wait on the alias being resolved and the main thread can keep the user informed. By using a modal progress window you've effectively blocked the user from doing anything but if they are not prepared to wait they have a way to abort the operation (which you have to implement of course). Just blocking without telling the user what's going on is worse than just beachballing - the beachball is after all a feedback mechanism that tells the user *something*. Even better: DON'T use a modal progress panel. The Finder has done the exact same thing correctly, by using a modeless progress panel (I have code for that on my web site, I think, UKProgressPanel or something like that). Start that action, show progress in a progress panel (and maybe start a spinner somewhere), let the rest of the app keep running, except for maybe disabling UI elements that are blocked until that other action has finished. This is OS X folks, we should try avoiding modality wherever possible. If your user can do other things in your app while such a process takes a while, LET THEM. That said, make sure the user knows that you're busy and that you heard their request. E.g. if you're taking longer, detect that and bring the (modeless) progress panel to the front after 4 seconds or so. It would be kinda silly if an action that is usually immediate but occasionally takes a minute to time out always showed a modal progress panel for a split-second. Users would get epileptic seizures from the title bar flashing ;-) Cheers, -- Uli Kusterer The Witnesses of TeachText are everywhere... http://www.zathras.de ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
How to use NSTimer correctly?
Hi, All, In my app I have a timer, created in the awakeFromNib and living until the app terminates. And I have some problem when I close the application. Here are my code snippets: - (void) awakeFromNib { ... processingTimer = YES; timer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(onTimer:) userInfo:nil repeats:YES]; ... } As I believe, everything is OK here... - (void) dealloc { processingTimer = NO; [timer invalidate]; .. } I'm not sure, if I must invalidate the timer, but think I should do it. - (void)onTimer:(NSTimer*)timer { ... // if (!processingTimer) return; // some procedure is going here, which updates the data for NSTableView // if (!processingTimer) return; // // Update results list in the NSTableView [fileView reloadData]; ^ here we had an exception within obc_msg_send() } Here is the onTimer: procedure, where I had an exception after I closed the application. I tried to remove timer invalidation from the dealloc, but nothing helped unless I've inserted a boolean var processingTimer, which should indicate whether our app still lives or it is slosing now. First I've added this var check only at the top of onTimer procedure, yet before the main calculating procedure call. That didn't helped. Then I've added yet another check right before the call of [NSTable reloadData]. And this helped. At least I've tried to run and close my app several times and I didn't see an exception. Also I tried to change timer interval, believing that my main procedure runs too slowly, so overlapped onTimer calls occur. But it makes no sense. So, what is the _correct_ way to do all that? Thanks. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: How to use NSTimer correctly?
First off, your object's -dealloc is never going to get called, because NSTimers retain their targets. (If your -dealloc is getting called, then you've got some memory management issues.) A breakpoint or an NSLog in -dealloc will tell you if it's getting called. I'm not sure, if I must invalidate the timer, but think I should do it. I always write the cleanup code even when not strictly necessary, as is the case with singletons. It helps later if it turns out you need multiple instances of the object - the cleanup's already there. Note though that since you didn't retain the timer, it'll be released as soon as you invalidate it, so it's a good idea to set the ivar to nil, so any subsequent attempts to access the timer won't crash your app. Here is the onTimer: procedure, where I had an exception after I closed the application. There are many kinds of exceptions. Which one? I tried to remove timer invalidation from the dealloc, but nothing helped unless I've inserted a boolean var processingTimer, which should indicate whether our app still lives or it is slosing now. First I've added this var check only at the top of onTimer procedure, yet before the main calculating procedure call. That didn't helped. Then I've added yet another check right before the call of [NSTable reloadData]. And this helped. At least I've tried to run and close my app several times and I didn't see an exception. This is getting kludgy, which is usually a sign that you're doing something wrong. Treat the source of the problem, not the symptom! What exception did you get? Also I tried to change timer interval, believing that my main procedure runs too slowly, so overlapped onTimer calls occur. But it makes no sense. Since this code is presumably single-threaded, it's impossible that one timer invocation could overlap another. So, what is the _correct_ way to do all that? For this situation, a good place to stick your cleanup code would be the NSApp's delegate method -applicationWillTerminate:, or you could observe the respective notification. David ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: How to use NSTimer correctly?
On 25.07.2009, at 18:48, Dave Keck wrote: First off, your object's -dealloc is never going to get called, because NSTimers retain their targets. If so, then where should I dealloc everything, I created in the awakeFromNib? I believed that dealloc will be called when my AppController will be released. But you say it is never released. Then what should I do? Is your suggestion about applicationWillTerminate etc. the correct way to go in this case? And where my AppController will be released? As far as I can understand I can't release it within applicationWillTerminate handler. Am I wrong? Should I write [self release] there? Thanks. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: How to use NSTimer correctly?
If so, then where should I dealloc everything, I created in the awakeFromNib? I believed that dealloc will be called when my AppController will be released. But you say it is never released. Then what should I do? In dealloc, as you do now. But you need to arrange for dealloc to be called, by making sure nothing (the timer) still retains you. -- 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
How to display the file's basic information in the columns of the table view?
Hi all, In my application, I want to drag the file into the table view. At the same time, display the file's basic information in the columns of the table view. Now, I got the basic information of the file and saved it in a NSDictionary object.The code is :theInfoDictionary =[NSDictionarydictionaryWithObjectsAndKeys:[filePath lastPathComponent], @name,[filePath pathExtension], @extension, modDate, @modifiedDate,nil]; In the - (BOOL)tableView: acceptDrop: row: dropOperation: method, I tried to insert the information Dictionary into the Array use the code [tableRecordsArray insertObject:infoDictionary atIndex:row+i];. But when I drop the file into the table view, the app exited immediately. But I do not know how to realize it. Note: The enclosure is the code of this application. I wish someone can find out the bug and amend it for me. Thank you. Any help greatly appreciated. Audio Player.rtf Description: Binary data ___ 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 display the file's basic information in the columns of the table view?
But when I drop the file into the table view, the app exited immediately. Find the crash report and look at it; if you don't figure it out from that, send another message here with the crash report. -- 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
Re: How to use NSTimer correctly?
On 25.07.2009, at 19:56, Scott Ribe wrote: If so, then where should I dealloc everything, I created in the awakeFromNib? I believed that dealloc will be called when my AppController will be released. But you say it is never released. Then what should I do? In dealloc, as you do now. But you need to arrange for dealloc to be called, by making sure nothing (the timer) still retains you. Could you explain it, how should I make the [dealloc] to be called? I've described, how I create a timer, so how should I free it to call dealloc? Should I explicitly call [self release] somewhere or should I do whatever else? Thanks. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: How to use NSTimer correctly?
On Jul 25, 2009, at 7:35 AM, Alexander Bokovikov wrote: On 25.07.2009, at 19:56, Scott Ribe wrote: If so, then where should I dealloc everything, I created in the awakeFromNib? I believed that dealloc will be called when my AppController will be released. But you say it is never released. Then what should I do? In dealloc, as you do now. But you need to arrange for dealloc to be called, by making sure nothing (the timer) still retains you. Could you explain it, how should I make the [dealloc] to be called? I've described, how I create a timer, so how should I free it to call dealloc? Should I explicitly call [self release] somewhere or should I do whatever else? Your original post said you're trying to do this at quit, but you can't rely on any object being sent -dealloc at application quit time. Do your cleanup in applicationWillTerminate:, either as the app delegate or by registering for the notification. You definitely don't want to use [self release]. http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmObjectOwnership.html#//apple_ref/doc/uid/2043-SW4 Important: When an application terminates, objects may not be sent a dealloc message since the process’s memory is automatically cleared on exit—it is more efficient simply to allow the operating system to clean up resources than to invoke all the memory management methods. This has implications for how you implement a dealloc method—see “Resource Management.” smime.p7s Description: S/MIME cryptographic signature ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: mouse entered/exited in nscollectionviewitem's view
hm, a quick answer to my own question: inserting [self performSelector:@selector(updateTrackingAreas) withObject:nil afterDelay:0.01]; into scrollWheel: seems to fix my problem. Ben On Jul 24, 2009, at 3:23 PM, Keith Duncan wrote: the setup code only gets called once and then none of the actually displayed views in the collection handle any of my intended mouse tracking. That's probably because your subclass of NSCollectionViewItem isn't getting created for each item. You can override -copyWithZone: to confirm this and fix it if need be. It's also prudent to ask for the mouse moved events to be sent too. Could anyone please point me into the right direction where to go on from here? Any help is appreciated. Yes, you'll also run into a problem when the user uses the scroll wheel to move around the collection view. The fix for this one is slightly more in depth. Your view under the mouse will first be send -scrollWheel: and it will work it's way up the responder chain to the scroll view from there. I inserted my NSCollectionViewItem subclass into the responder chain between the item view and it's superview so that the controller was sent -scrollWheel: before the scroll view. In that method I tracked the position of the mouse converting from window coordinates to collection view coordinates and determined which view the mouse was hovering over. Once you've done that it's a simple matter of posting a notification internal to the collection view item subclass to coordinate the hovering state between controllers so that only one is showing the hovering state at a given time. Keith ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: NSTableView - populating from C procedure
On 25 Jul 2009, at 03:56, Uli Kusterer wrote: I don't think you can use sizeof() on a pointer passed as a parameter, though. That only works on variables in the current scope. That pointer could point at anything, so the compiler has no idea whether it points at the stack or the heap. Even if it generated specialized code for the stack case, what code would it generate for the heap case? sizeof() is independent from malloc(), NewPtr() and all the other allocator schemes the OS knows, sizeof() wouldn't know which one to use. sizeof() does exactly one thing, which is return the amount of storage allocated *by the compiler* for its argument. Despite appearances, it is not a function: it's a compiler directive, and compiles to a constant value. For example: char charArray[24]; sizeof(charArray) = 24 int intArray[16]; sizeof(intArray) = 64 char *charArrayPointer = charArray; int *intArrayPointer = intArray; sizeof(charArrayPointer) = sizeof(intArrayPointer) = 4 (8 on 64-bit builds) What's happened here? Taking the sizeof() a pointer doesn't tell you anything about the size of the object it's pointing to - all it can tell you is how big *the pointer itself* is. You can dereference a pointer in a sizeof() expression, but only in a limited fashion: sizeof(*charArrayPointer) = 1 sizeof(*intArrayPointer) = 4 Confused? Keep in mind that *charArrayPointer is equivalent to charArrayPointer[0] - it returns the first element, not the whole original array. ___ 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: NSDictionary crash
On Sat, Jul 25, 2009 at 7:04 PM, slasktrattena...@gmail.comslasktrattena...@gmail.com wrote: Hello, I have never been able to reproduce this one myself, but have received a number of similar crash reports. The crash occurs on this line (detached thread): NSDictionary *iTunesLib = [[NSDictionary alloc] initWithContentsOfFile:libPath]; libPath is a retained ivar, guaranteed to be a valid path, never nil. Thread 14 Crashed: 0 com.apple.CoreFoundation 0x90451ac3 __CFFromUTF8 + 675 1 com.apple.CoreFoundation 0x904e2a3f __CFStringDecodeByteStream3 + 1967 2 com.apple.CoreFoundation 0x904ca069 __CFStringCreateImmutableFunnel3 + 409 3 com.apple.CoreFoundation 0x904cb2ce CFStringCreateWithBytes + 94 4 com.apple.CoreFoundation 0x904a842b _CFPropertyListCreateFromXMLData + 379 5 com.apple.CoreFoundation 0x904a91bb CFPropertyListCreateFromXMLData + 59 6 com.apple.Foundation 0x958d04be _NSParseObjectFromASCIIPropertyListOrSerialization + 46 7 com.apple.Foundation 0x958d0346 +[NSDictionary(NSDictionary) newWithContentsOf:immutable:] + 166 8 com.apple.CoreFoundation 0x9052457f -[__NSPlaceholderDictionary initWithContentsOfFile:] + 63 9 com.my.app 0x0003d4b7 0x1000 + 246967 10 com.my.app 0x0003d19a 0x1000 + 246170 11 com.apple.Foundation 0x958b2e0d -[NSThread main] + 45 12 com.apple.Foundation 0x958b29b4 __NSThread__main__ + 308 13 libSystem.B.dylib 0x916bf155 _pthread_start + 321 14 libSystem.B.dylib 0x916bf012 thread_start + 34 Thread 14 crashed with X86 Thread State (32-bit): eax: 0x ebx: 0x90451831 ecx: 0xf9c1 edx: 0x edi: 0x024fe617 esi: 0x003c ebp: 0xb01bf4d8 esp: 0xb01bf450 ss: 0x001f efl: 0x00010206 eip: 0x90451ac3 cs: 0x0017 ds: 0x001f es: 0x001f fs: 0x001f gs: 0x0037 cr2: 0x Any ideas? Thanks in advance. PS. Should have said it's a sigbus Exception Type: EXC_BAD_ACCESS (SIGBUS) Exception Codes: KERN_PROTECTION_FAILURE at 0x Crashed Thread: 14 ___ 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 NSTimer correctly?
On Jul 25, 2009, at 10:04 AM, Alexander Bokovikov wrote: On 25.07.2009, at 21:29, Adam R. Maxwell wrote: Your original post said you're trying to do this at quit, but you can't rely on any object being sent -dealloc at application quit time. Do your cleanup in applicationWillTerminate:, either as the app delegate or by registering for the notification. You definitely don't want to use [self release]. Probably I've found the reason. The Release when closed flag was set in the Window properties. Therefore my NSTableView has been released as soon as I clicked window close button, but other application parts like AppController still were active and timer still generated its events. As far as I understand now, this flag Release when closed may be set only for a window without any interaction, like a message window, etc. I's not correctly to set this flag, when there are some objects, referring to the closed window content. This is just my case. Release When Closed is covered here: http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmNibObjects.html Also, check the API doc for -[NSWindow setReleasedWhenClosed:]. There are some subtleties associated with it, and I personally think it's a nuisance. Another question arrives - who will release this window and when it will be released? My AppController is set as NSApp delegate, and it responds to applicationShouldTerminateAfterLastWindowClosed message YES. Does it mean that NSApp will release this my window? Why are you worrying about this? As I said previously, if your application is quitting, dealloc may not be called. Just fulfill your part of the memory contract, and release the window if you own it. Also I see windowWillClose message in the API reference. It's described : Sent by the default notification center. What does it mean? What is this default notification center and how to get this message? http://lmgtfy.com/?q=default+notification+center Try the second URL. Should I set my AppController, as the window delegate to receive it? Probably. Try it and see what happens. smime.p7s Description: S/MIME cryptographic signature ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: I need a milder application badge (solution)
On Jul 25, 2009, at 1:58 AM, Jay Reynolds Freeman jay_reynolds_free...@mac.com wrote: Well, mea culpa, I have not been speaking clearly; what I want to badge is not the dock tile but the dock icon, Not sure I understand what you're talking about. Do you mean to modify the application's icon even when it isn't running? There is no API to achieve this at this time. --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: NSDictionary crash
On Jul 25, 2009, at 10:04 AM, slasktrattena...@gmail.com wrote: I have never been able to reproduce this one myself, but have received a number of similar crash reports. The crash occurs on this line (detached thread): NSDictionary *iTunesLib = [[NSDictionary alloc] initWithContentsOfFile:libPath]; libPath is a retained ivar, guaranteed to be a valid path, never nil. Three possibilities off the top of my head: - file is corrupt - your process ran out of memory - the file was deleted or rewritten while -initWithContentsOfFile: was in the midst of reading it 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: I need a milder application badge (solution)
What I want to do is modify the dock icon while the application running. The only interface I can find to do this is NSApp.setApplicationIconImage: , which requires an NSImage. I have no way to get at the actual view being used to draw the dock icon, in order to subclass it; I have to create a new NSImage somehow, and pass that to setApplicationIconImage. There has been some confusion in the discussion so far, most of it my fault for using the wrong terminology by mistake. What I want to modify is the dock ICON, not the dock TILE. The doc tile is the tiny image of the application main window that appears in the dock when you minimize the application. The dock icon is (usually) the regular application icon, that appears in the dock when the application is launched, and which you may have sitting there permanently for ease of access to a commonly used application. There is an interface for making run-time changes to the view used for drawing the dock tile; namely NSDockTile.setContentView: , but I do not find such an interface for the dock icon. This discussion is in some jeopardy of ratholing into off-list topics like proper use of the dock and what constitutes consistent user interface behavior for application icons. Maybe we should stick to a basic technical question, which is possibly of broader interest: What is the Cocoa way to alter an NSImage dynamically (or perhaps alter a copy of an original image), at run-time, while preserving as transparent any transparent areas it may have to begin with? The best I have got at the moment is outrageous hackery at the pixel level in the bit map; there ought to be something better ... -- Jay Reynolds Freeman - jay_reynolds_free...@mac.com http://web.mac.com/jay_reynolds_freeman (personal web site) Well, mea culpa, I have not been speaking clearly; what I want to badge is not the dock tile but the dock icon, Not sure I understand what you're talking about. Do you mean to modify the application's icon even when it isn't running? There is no API to achieve this at this time. --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: NSDictionary crash
On Sat, Jul 25, 2009 at 7:53 PM, Bill Bumgarnerb...@mac.com wrote: On Jul 25, 2009, at 10:04 AM, slasktrattena...@gmail.com wrote: I have never been able to reproduce this one myself, but have received a number of similar crash reports. The crash occurs on this line (detached thread): NSDictionary *iTunesLib = [[NSDictionary alloc] initWithContentsOfFile:libPath]; libPath is a retained ivar, guaranteed to be a valid path, never nil. Three possibilities off the top of my head: - file is corrupt - your process ran out of memory - the file was deleted or rewritten while -initWithContentsOfFile: was in the midst of reading it I find the third option the most likely: iTunes rewrites the data file frequently. Is there a way to lock the file while reading it, or detect if it is being modified, or suchlike? Thanks. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: I need a milder application badge (solution)
On Jul 25, 2009, at 10:54 AM, Jay Reynolds Freeman jay_reynolds_free...@mac.com wrote: The doc tile is the tiny image of the application main window that appears in the dock when you minimize the application. The dock icon is (usually) the regular application icon, that appears in the dock when the application is launched, and which you may have sitting there permanently for ease of access to a commonly used application. This is incorrect. The dock tile is the thing that sits in the dock; by default it draws the application's icon image (or the image in the app bundle when the app isn't running). There is no such thing as a dock icon that exists as a concept separate from dock tile. There is an interface for making run-time changes to the view used for drawing the dock tile; namely NSDockTile.setContentView: , but I do not find such an interface for the dock icon. You have two choices: change your application's icon using - [NSApplication setApplicationIconImage:], or customize the dock tile returned by -[NSApplication dockTile]. Neither of these changes will persist after your application quits. What is the Cocoa way to alter an NSImage dynamically (or perhaps alter a copy of an original image), at run-time, while preserving as transparent any transparent areas it may have to begin with? You've touched on a few separate topics here. Sounds like you might want to read the Quartz documentation to get an idea of how graphics composition works. And play around with Photoshop a bit; the Quartz model is quite similar. --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: NSDictionary crash
On Jul 25, 2009, at 11:00 AM, slasktrattena...@gmail.com slasktrattena...@gmail.com wrote: I find the third option the most likely: iTunes rewrites the data file frequently. Is there a way to lock the file while reading it, or detect if it is being modified, or suchlike? Thanks. You aren't guaranteed that the iTunes library file will always be a plist. The correct recommendation, which will also solve your issue, is to use Apple Events to get the information you need. In the general case, since you didn't write -[NSDictionary initWithContentsOfFile:], you can't make it safe. You'll have to open the file and read it's data yourself, then hand that off to the NSDictionary initializer (or perhaps NSPropertyListSerialization). --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: I need a milder application badge (solution)
On Sat, Jul 25, 2009 at 1:54 PM, Jay Reynolds Freemanjay_reynolds_free...@mac.com wrote: What I want to do is modify the dock icon while the application running. The only interface I can find to do this is NSApp.setApplicationIconImage: , which requires an NSImage. I have no way to get at the actual view being used to draw the dock icon, in order to subclass it; I have to create a new NSImage somehow, and pass that to setApplicationIconImage. You don't need to subclass anything just to draw into an NSImage. You can call an NSImage's -lockFocus method to direct all the usual drawing functions and methods to draw into that image, instead of into an onscreen view. Don't forget to call -unlockFocus when you're done! So, what you want to do is, get the default image, -copy it and -autorelease the copy, send the copy a -lockFocus, draw whatever content you want to add to the icon, using all the usual functions methods you'd have used in a subclass' -drawRect: method, send the copy a -unlockFocus, send the copy to -setApplicationIconImage:. sherm-- -- Cocoa programming in Perl: http://camelbones.sourceforge.net ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Unit testing question
There are a lot of good tutorials on unit testing with XCode. What you will probably need is a good mocking framework for the interaction. A list from this list: http://www.mail-archive.com/cocoa-dev@lists.apple.com/msg09642.html OCMock: http://www.mulle-kybernetik.com/software/OCMock/ Once you get past the initial phases another good tool is the Google Toolbox (for iPhone Unit Testing) and Hamcrest for better asserts. Hamcrest: http://code.google.com/p/hamcrest/ Google Toolbox: http://code.google.com/p/google-toolbox-for-mac/ Scott On Jul 25, 2009, at 1:17 AM, lorenzo7...@gmail.com wrote: I'd like to add unit testing to my app, but I'ma little bit unclear on the concept. I've looked at Apple's docs on the Sentest framework and had no trouble getting the sample project working, but I lose it when translating the concepts to my particular application. I've seen some sample projects around the net that use the Sentest framework, but the the unit tests are trivially simple, asserting that 1+1 = 2, for example. What I really need is a sample project of some complexity that uses real unit tests against the project. Can anyone help me out here? My app is an NSStatusItem that retrieves data from the internet, and displays it in the NSStatusItem's menu. The only real user interface besides that is the preferences window. Should my unit test manually invoke the IBAction that displays the window and then fill its fields with values I need to test? TIA ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/scottdensmore%40mac.com This email sent to scottdensm...@mac.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Fwd: I need a milder application badge (solution)
What Sherm suggests is exactly what I described as my solution, and it does work, with one serious problem: Capturing the image that gets drawn in the manner described *also* captures whatever background lies beyond the transparent portions of the image, and that is not what I want. That is why I have to hack the bitmap after capturing it. If I set a particular background color for the view where I am drawing the image, then the newly-captured image shows that color where the original image was transparent. If I tell that view not to draw its background, or set its background color to transparent, then I get the background color of the window at the base of the view hierarchy. And if tell that window not to draw its background, or to use a transparent background color, then the transparent portions of the original image come out dead black in the copy. (I suspect that dead black is the color of off-screen portions of the Mac console.) -- Jay Reynolds Freeman - jay_reynolds_free...@mac.com http://web.mac.com/jay_reynolds_freeman (personal web site) On Jul 25, 2009, at 11:25 AM, Sherm Pendley wrote: On Sat, Jul 25, 2009 at 1:54 PM, Jay Reynolds Freemanjay_reynolds_free...@mac.com wrote: What I want to do is modify the dock icon while the application running. The only interface I can find to do this is NSApp.setApplicationIconImage: , which requires an NSImage. I have no way to get at the actual view being used to draw the dock icon, in order to subclass it; I have to create a new NSImage somehow, and pass that to setApplicationIconImage. You don't need to subclass anything just to draw into an NSImage. You can call an NSImage's -lockFocus method to direct all the usual drawing functions and methods to draw into that image, instead of into an onscreen view. Don't forget to call -unlockFocus when you're done! So, what you want to do is, get the default image, -copy it and -autorelease the copy, send the copy a -lockFocus, draw whatever content you want to add to the icon, using all the usual functions methods you'd have used in a subclass' -drawRect: method, send the copy a -unlockFocus, send the copy to -setApplicationIconImage:. sherm-- -- Cocoa programming in Perl: http://camelbones.sourceforge.net ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: I need a milder application badge (solution)
If I set a particular background color for the view where I am drawing the image... Sherm's suggestion does not involve drawing into a view at all... -- 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
[iPhone] Why can't a UITextField be its own delegate?
Hello all, I need to create a subclass of UITextField for a text field that performs some control over its own editing. The obvious idea is to make the subclass instance set itself up as its own delegate, but that freezes the app as soon as the delegate method - textFieldDidBeginEditing returns. Looking at Activity Monitor, the CPU usage of the app goes up to nearly 100%. I've since created the most trivial app with a UITextField subclass that conforms to the UITextFieldDelegate protocol and which sets itself up as its own delegate and, sure enough, the app freezes. Here's the subclass. Set up a project then add a text field to a view and make its class be CustomTextField. Compile and run, and watch it freeze when you attempt to edit the text in the field. So... why can't the field be its own delegate? Thanks in advance. Wagner // CustomTextField.h: #import UIKit/UIKit.h @interface CustomTextField: UITextField UITextFieldDelegate { } @end // CustomTextField.m: #import CustomTextField.h @implementation CustomTextField - (void) awakeFromNib { super.delegate = self; super.text = @Hello world; NSLog(@awakeFromNib called - delegate set to self); } // = = = = = // - (BOOL) textField: (UITextField*) text_field shouldChangeCharactersInRange: (NSRange) range replacementString: (NSString*) string { NSLog(@-textField: shouldChangeCharactersInRange: replacementString:); return YES; } // = = = = = // - (BOOL) textFieldShouldBeginEditing: (UITextField*) text_field { NSLog(@-textFieldShouldBeginEditing:); return YES; } // = = = = = // - (void) textFieldDidBeginEditing: (UITextField*) text_field { NSLog(@-textFieldDidBeginEditing:); } // = = = = = // - (BOOL) textFieldShouldEndEditing: (UITextField*) text_field { NSLog(@-textFieldShouldEndEditing:); return YES; } // = = = = = // - (void) textFieldDidEndEditing: (UITextField*) text_field { NSLog(@-textFieldDidEndEditing:); } // = = = = = // - (BOOL) textFieldShouldClear: (UITextField*) text_field { NSLog(@-textFieldShouldClear:); return YES; } // = = = = = // - (BOOL) textFieldShouldReturn: (UITextField*) text_field { NSLog(@-textFieldShouldReturn:); [self resignFirstResponder]; return YES; } // = = = = = // @end ___ 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: Unit testing question
On Jul 25, 2009, at 1:17 AM, lorenzo7...@gmail.com wrote: I'd like to add unit testing to my app, but I'ma little bit unclear on the concept. I've looked at Apple's docs on the Sentest framework and had no trouble getting the sample project working, but I lose it when translating the concepts to my particular application. I've seen some sample projects around the net that use the Sentest framework, but the the unit tests are trivially simple, asserting that 1+1 = 2, for example. What I really need is a sample project of some complexity that uses real unit tests against the project. Can anyone help me out here? This is not exactly unit testing per se, but if you want to exercise your app thru its interface, you might want to consider GUI scripting. With GUI scripting you can both drive and read an application's interface through Apple events. One good way to implement a battery of GUI scripting tests is with rb-appscript. m. -- matt neuburg, phd = m...@tidbits.com, http://www.tidbits.com/matt/ A fool + a tool + an autorelease pool = cool! AppleScript: the Definitive Guide - Second Edition! http://www.tidbits.com/matt/default.html#applescriptthings ___ 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: I need a milder application badge (solution)
You have two choices: change your application's icon using -[NSApplication setApplicationIconImage:], or customize the dock tile returned by -[NSApplication dockTile]. Neither of these changes will persist after your application quits. I do not want to change the dockTile, and no public method of NSDockTile appears to change the dock icon in any case. I am indeed using -[NSApplication setApplicationIconImage:], my problem is creating a new image that has the correct areas transparent. What is the Cocoa way to alter an NSImage dynamically (or perhaps alter a copy of an original image), at run-time, while preserving as transparent any transparent areas it may have to begin with? You've touched on a few separate topics here. Sounds like you might want to read the Quartz documentation to get an idea of how graphics composition works. And play around with Photoshop a bit; the Quartz model is quite similar. I am sure I can do it; it's all just ones and zeros and I have access to all the bits. But I am not a graphics specialist and I am reluctant to become one. (And I have never used Photoshop or anything remotely like it.) I am just looking for a way to alter images dynamically, at run-time, that is as easy as putting up an offscreen window/view hierarchy and drawing into it. I would like to be able to use something like the capabilities of NSView for superimposing different things on my new image. I would like to work the problem at as high a level as I can. In a separate comment, Scott Ribe has pointed out that I can draw to an image directly by instantiating it and locking focus. He is right, I did not read Sherm's suggestion carefully. However, I was doing my drawing in a view/window hierarchy in order to make it easy to superimpose a badge-like string on my image (I just put an NSText on top of the view that contains the image and write the string with a background of appropriate color.) I need to thank you all for being patient with someone who is unfamiliar with low-level Macintosh graphics; I need all the help I can get. --Kyle Sluder -- Jay Reynolds Freeman - jay_reynolds_free...@mac.com http://web.mac.com/jay_reynolds_freeman (personal web site) ___ 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/jay_reynolds_freeman%40mac.com This email sent to jay_reynolds_free...@mac.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: [iPhone] Why can't a UITextField be its own delegate?
I won't pretend to know the answer, but this struck me as odd: On Jul 25, 2009, at 3:06 PM, WT wrote: - (void) awakeFromNib { super.delegate = self; super.text = @Hello world; NSLog(@awakeFromNib called - delegate set to self); } Shouldn't it be [self setDelegate: self]? I wouldn't think you'd have an actual 'super' object available to perform the delegate methods. But I probably don't understand. Brian ___ 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: NSDictionary crash
On Sat, Jul 25, 2009 at 8:20 PM, Kyle Sluderkyle.slu...@gmail.com wrote: On Jul 25, 2009, at 11:00 AM, slasktrattena...@gmail.com slasktrattena...@gmail.com wrote: I find the third option the most likely: iTunes rewrites the data file frequently. Is there a way to lock the file while reading it, or detect if it is being modified, or suchlike? Thanks. You aren't guaranteed that the iTunes library file will always be a plist. You mean because it might be rewritten or corrupted while my app is reading it, or because the format might change in the future? The correct recommendation, which will also solve your issue, is to use Apple Events to get the information you need. Yes, but then iTunes would have to be running. Plus it's a lot slower. I believe the sole purpose of the xml file (as opposed to the actual iTunes library file) is for third parties to be able to access iTunes data without querying iTunes.app. In the general case, since you didn't write -[NSDictionary initWithContentsOfFile:], you can't make it safe. You'll have to open the file and read it's data yourself, then hand that off to the NSDictionary initializer (or perhaps NSPropertyListSerialization). If I get the data with e g NSData's initWithContentsOfFile:, how would I initialize the dictionary? I don't see any dictionaryWithData: or suchlike in NSDictionary. Would I have to do the parsing myself? Also, is the NSData equivalent any safer than NSDictionary's? It's initWithContentsOfFile: method is documented to return An initialized object—which might be different than the original receiver—that contains the dictionary at path, or nil if there is a file error or if the contents of the file are an invalid representation of a dictionary. There's no mention of a potential crash. Should I file a bug? I found an example on reading property lists using Core Foundation functions in the Property List Programming Guide (http://developer.apple.com/documentation/Cocoa/Conceptual/PropertyLists/ReadWritePlistData/ReadWritePlistData.html#//apple_ref/doc/uid/1048i-CH8-SW1). Is this a safer way to get the data than relying on factory methods? Thanks! ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: NSDictionary crash
On Jul 25, 2009, at 11:20 AM, Kyle Sluder wrote: On Jul 25, 2009, at 11:00 AM, slasktrattena...@gmail.com slasktrattena...@gmail.com wrote: I find the third option the most likely: iTunes rewrites the data file frequently. Is there a way to lock the file while reading it, or detect if it is being modified, or suchlike? Thanks. You aren't guaranteed that the iTunes library file will always be a plist. The correct recommendation, which will also solve your issue, is to use Apple Events to get the information you need. In the general case, since you didn't write -[NSDictionary initWithContentsOfFile:], you can't make it safe. You'll have to open the file and read it's data yourself, then hand that off to the NSDictionary initializer (or perhaps NSPropertyListSerialization). --Kyle Sluder An alternative would be to copy the file to a temporary location, and then read from it, as long as you are okay with the version in memory being slightly out-of-date. However, as Kyle points out, this is not necessarily a safe way to do things going forward, and Apple Events is probably what you want. - Alex Heinz ___ 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: NSDictionary crash
On Sat, Jul 25, 2009 at 9:28 PM, Alexander Heinzahei...@johnshopkins.edu wrote: On Jul 25, 2009, at 11:20 AM, Kyle Sluder wrote: On Jul 25, 2009, at 11:00 AM, slasktrattena...@gmail.com slasktrattena...@gmail.com wrote: I find the third option the most likely: iTunes rewrites the data file frequently. Is there a way to lock the file while reading it, or detect if it is being modified, or suchlike? Thanks. You aren't guaranteed that the iTunes library file will always be a plist. The correct recommendation, which will also solve your issue, is to use Apple Events to get the information you need. In the general case, since you didn't write -[NSDictionary initWithContentsOfFile:], you can't make it safe. You'll have to open the file and read it's data yourself, then hand that off to the NSDictionary initializer (or perhaps NSPropertyListSerialization). --Kyle Sluder An alternative would be to copy the file to a temporary location, and then read from it, as long as you are okay with the version in memory being slightly out-of-date. Yes, that's okay. But how would I know the file is readable at the time I copy it? However, as Kyle points out, this is not necessarily a safe way to do things going forward, and Apple Events is probably what you want. - Alex Heinz ___ 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: [iPhone] Why can't a UITextField be its own delegate?
On Jul 25, 2009, at 9:17 PM, Brian Slick wrote: I won't pretend to know the answer, but this struck me as odd: On Jul 25, 2009, at 3:06 PM, WT wrote: - (void) awakeFromNib { super.delegate = self; super.text = @Hello world; NSLog(@awakeFromNib called - delegate set to self); } Shouldn't it be [self setDelegate: self]? I wouldn't think you'd have an actual 'super' object available to perform the delegate methods. But I probably don't understand. Brian The reason is simple, though probably not obvious. I still might need the text field to have an outside delegate, which I maintain by having an additional outlet reserved for that delegate. Then, I override -delegate to return that outlet and -setDelegate: to set it. That way, the field can be its own true delegate and do its job, while also allowing an outside object to serve as a delegate and participate in the editing session. As far as the outside world is concerned, it's business as usual. But once I have an overridden -setDelegate:, I can't use self.delegate = self to set the field as its own true delegate, because that will execute the overridden method. Wagner ___ 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: NSDictionary crash
On Jul 25, 2009, at 12:25 PM, slasktrattena...@gmail.com slasktrattena...@gmail.com wrote: You mean because it might be rewritten or corrupted while my app is reading it, or because the format might change in the future? I was referring to the latter. Of course you've already noted the former. Yes, but then iTunes would have to be running. Plus it's a lot slower. I believe the sole purpose of the xml file (as opposed to the actual iTunes library file) is for third parties to be able to access iTunes data without querying iTunes.app. Unfortunately the XML file is an implementation detail on whichbwe cannot rely. It would be nice if Apple opened their iLife framework for us to use for this purpose -- file a Radar and/or contact DTS. It's a known issue, but it helps to let Apple know that yet another developer has encountered this problem. If I get the data with e g NSData's initWithContentsOfFile:, how would I initialize the dictionary? I don't see any dictionaryWithData: or suchlike in NSDictionary. Would I have to do the parsing myself? As I mentioned, look at NSPropertyListSerialization. NSDictionary is a plist type and can be decoded from an NSData. Also, is the NSData equivalent any safer than NSDictionary's? It's initWithContentsOfFile: method is documented to return An initialized object—which might be different than the original receiver—that contains the dictionary at path, or nil if there is a file error or if the contents of the file are an invalid representation of a dictionary. There's no mention of a potential crash. Should I file a bug? You can ensure the safety of the file before using NSData. You can't when using NSDictionary's convenience constructor. One issue that you will encounter, however, is that iTunes is incredibly picky about its file store. It will throw a tantrum if it can't write to its database. The best answer at the moment is to file a Radar and use Apple Events. --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: [iPhone] Why can't a UITextField be its own delegate?
Wow, this all sounds very convoluted. If you must have two levels of delegation (which sounds like flawed design, to me) then I would suggest doing it in a more straightforward manner. That is, make a delegate for UITextField, and then have another delegate protocol for that object so it can have its own delegate. Even better, just wrap everything you need into the object you set as delegate to UITextField and don't try to shove weird things into a subclass. Luke On Jul 25, 2009, at 12:39 PM, WT wrote: The reason is simple, though probably not obvious. I still might need the text field to have an outside delegate, which I maintain by having an additional outlet reserved for that delegate. Then, I override -delegate to return that outlet and - setDelegate: to set it. That way, the field can be its own true delegate and do its job, while also allowing an outside object to serve as a delegate and participate in the editing session. As far as the outside world is concerned, it's business as usual. But once I have an overridden -setDelegate:, I can't use self.delegate = self to set the field as its own true delegate, because that will execute the overridden method. Wagner ___ ___ 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: NSDictionary crash
On Sat, Jul 25, 2009 at 9:39 PM, Kyle Sluderkyle.slu...@gmail.com wrote: As I mentioned, look at NSPropertyListSerialization. NSDictionary is a plist type and can be decoded from an NSData. OK, thanks. Also, is the NSData equivalent any safer than NSDictionary's? It's initWithContentsOfFile: method is documented to return An initialized object—which might be different than the original receiver—that contains the dictionary at path, or nil if there is a file error or if the contents of the file are an invalid representation of a dictionary. There's no mention of a potential crash. Should I file a bug? You can ensure the safety of the file before using NSData. You can't when using NSDictionary's convenience constructor. Sorry for being ignorant, but how do I ensure the safety of the file? I don't see anything about this in the NSData API. One issue that you will encounter, however, is that iTunes is incredibly picky about its file store. It will throw a tantrum if it can't write to its database. Hmm, OK. I suppose I could go for Apple Events when iTunes is running and only read the xml data when it's not. Shame about the speed, though. The best answer at the moment is to file a Radar I will. Thanks a lot for your help. ___ 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: [iPhone] Why can't a UITextField be its own delegate?
Convoluted? I don't see it that way. This particular text field needs to limit its number of characters to a given interval. Why should any other object have to deal with that problem when the field itself can take care of it? Still, it might be the case, though it also might not be the case, that another object wants to participate in the editing session. The flow of events here is as follows: the field takes care of its own business first (limiting the number of characters) and then allows the delegate, if any, to have its shot at the editing process. And since limiting the number of characters is always going to happen but having extra work might not, it does not make sense to me to burden an extra object with both tasks. Let the field take care of its own business since it can do so cleanly. All other objects shouldn't care. In any case, none of this has anything to do with the problem I mentioned. The sample application has no extra delegates and, in fact, does nothing whatsoever other than having the field be its own delegate. Incidentally, I tried the same thing with a Mac application and it works fine. It's only under the iPhone SDK that setting a text field to be its own delegate causes a problem. The documentation for UITextField says nothing about any restrictions about which objects can and cannot be the field delegate and I can't see a reason why the field can't be its own delegate, so I'm inclined to think that this is a real bug in the iPhone SDK. As usual, though, I'd like to hear other people's input on the matter, because I might be missing something. Wagner On Jul 25, 2009, at 9:47 PM, Luke the Hiesterman wrote: Wow, this all sounds very convoluted. If you must have two levels of delegation (which sounds like flawed design, to me) then I would suggest doing it in a more straightforward manner. That is, make a delegate for UITextField, and then have another delegate protocol for that object so it can have its own delegate. Even better, just wrap everything you need into the object you set as delegate to UITextField and don't try to shove weird things into a subclass. Luke On Jul 25, 2009, at 12:39 PM, WT wrote: The reason is simple, though probably not obvious. I still might need the text field to have an outside delegate, which I maintain by having an additional outlet reserved for that delegate. Then, I override -delegate to return that outlet and - setDelegate: to set it. That way, the field can be its own true delegate and do its job, while also allowing an outside object to serve as a delegate and participate in the editing session. As far as the outside world is concerned, it's business as usual. But once I have an overridden -setDelegate:, I can't use self.delegate = self to set the field as its own true delegate, because that will execute the overridden method. Wagner ___ ___ 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: NSDictionary crash
On Jul 25, 2009, at 12:59 PM, slasktrattena...@gmail.com slasktrattena...@gmail.com wrote: Sorry for being ignorant, but how do I ensure the safety of the file? I don't see anything about this in the NSData API. Look at other APIs in the system. The point is to wind up with an NSData; this doesn't mean the API you use has to be in the NSData class. Hmm, OK. I suppose I could go for Apple Events when iTunes is running and only read the xml data when it's not. Shame about the speed, though. Also not a safe option; other Apple apps can access the XML file, includeing CoreServices (for the media picker in the Open panel). Unfortunately we don't know how they do it and therefore can't be guaranteed that they won't also break if you have a lock on the database file. Apple Events will take care of launching iTunes for you. Its launch time is much less of a burden now than it was before the update a few months ago. --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: NSDictionary crash
On Sat, Jul 25, 2009 at 10:21 PM, Kyle Sluderkyle.slu...@gmail.com wrote: Also not a safe option; other Apple apps can access the XML file, includeing CoreServices (for the media picker in the Open panel). Unfortunately we don't know how they do it and therefore can't be guaranteed that they won't also break if you have a lock on the database file. Thanks for the heads up. I'm afraid the end users would be upset if the app required iTunes to be running all of a sudden, though. So I'll try with the Core Foundation methods for now (without locking the file). Hopefully it won't result in a crash if the file is modified while read, just a NULL pointer or invalid data (which is fine considering how often the data is read, I'll just rely on the last valid object). CFPropertyListRef CreateMyPropertyListFromFile( CFURLRef fileURL ) { CFPropertyListRef propertyList; CFStringRef errorString; CFDataRef resourceData; Boolean status; SInt32errorCode; // Read the XML file. status = CFURLCreateDataAndPropertiesFromResource( kCFAllocatorDefault, fileURL, resourceData,// place to put file data NULL, NULL, errorCode); // Reconstitute the dictionary using the XML data. propertyList = CFPropertyListCreateFromXMLData( kCFAllocatorDefault, resourceData, kCFPropertyListImmutable, errorString); if (resourceData) { CFRelease( resourceData ); } else { CFRelease( errorString ); } return propertyList; } ___ 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 tell an object to notify its KVOs that one of its properties needs to be re-cached...
When we have an object who has a property that's generated based on other properties, usually we implement the +keyPathsForValuesAffecting[PropertyName] class method. What I'm trying to do is basically the same thing for a property on my NSManagedObject, but traversing a relationship. My model is simple; I have two Entities, App and Version (I'm creating an appcast-generating app). There is a dynamic property - (NSString*) appcast; which is generated based on all the details of the app and its versions relationships. When the App's properties are changed, the -appcast string is re-cached, and all bindings are updated appropriately, simply because I implemented +keyPathsForValuesAffectingAppcast, as per the statement above. However, when any properties on any of a specific App's Versions (to-many relationship) change, the -appcast property is not generated appropriately. Is there a way to have this dynamic property re-cached any time certain (any) properties on its versions relationship are changed? So far, I've tried to include key paths such as versions.versionNumber in the NSSet returned from the aforementioned method, but that just throws an exception that the key versionNumber does not exist on NSSet. Thanks in advance for your responses, this has been boggling me for many hours. -Steven, www.degutis.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: [iPhone] Why can't a UITextField be its own delegate?
On Sat, Jul 25, 2009 at 1:14 PM, WTjrca...@gmail.com wrote: This particular text field needs to limit its number of characters to a given interval. Why should any other object have to deal with that problem when the field itself can take care of it? Still, it might be the case, though it also might not be the case, that another object wants to participate in the editing session. The flow of events here is as follows: the field takes care of its own business first (limiting the number of characters) and then allows the delegate, if any, to have its shot at the editing process. In the Cocoa world, it makes more sense to hook up a delegate to do this work, especially if this is a one-off control. It comes down to thinking of it as a text field which limits number of characters rather than a number-of-characters-limited text field. If you need this behavior in multiple places in your application, you can factor out the delegate behavior into a superclass and have your delegates derive from it, calling this method when necessary. --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: [iPhone] Why can't a UITextField be its own delegate?
That approach makes much more sense. Luke On Jul 25, 2009, at 2:44 PM, Kyle Sluder wrote: On Sat, Jul 25, 2009 at 1:14 PM, WTjrca...@gmail.com wrote: This particular text field needs to limit its number of characters to a given interval. Why should any other object have to deal with that problem when the field itself can take care of it? Still, it might be the case, though it also might not be the case, that another object wants to participate in the editing session. The flow of events here is as follows: the field takes care of its own business first (limiting the number of characters) and then allows the delegate, if any, to have its shot at the editing process. In the Cocoa world, it makes more sense to hook up a delegate to do this work, especially if this is a one-off control. It comes down to thinking of it as a text field which limits number of characters rather than a number-of-characters-limited text field. If you need this behavior in multiple places in your application, you can factor out the delegate behavior into a superclass and have your delegates derive from it, calling this method when necessary. --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
Multiple delegates Window
I was wondering if it is possible to connect more than one delegate from the Window in IB. When I create a new Cocoa application in XCode, the Delegate_AppDelegate.m/h is created automatically. I would like to add a second object with specific functionality as a delegate object. How do I do this? 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: Multiple delegates Window
On Sat, Jul 25, 2009 at 2:55 PM, Gevikmac...@xs4all.nl wrote: How do I do this? You don't. Read up on the delegate pattern again, and how it's implemented in Cocoa. You can't have one pointer point at two different things, so therefore you can't have two delegates hooked up to one outlet. --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: [iPhone] Why can't a UITextField be its own delegate?
On Jul 25, 2009, at 11:44 PM, Kyle Sluder wrote: On Sat, Jul 25, 2009 at 1:14 PM, WTjrca...@gmail.com wrote: This particular text field needs to limit its number of characters to a given interval. Why should any other object have to deal with that problem when the field itself can take care of it? Still, it might be the case, though it also might not be the case, that another object wants to participate in the editing session. The flow of events here is as follows: the field takes care of its own business first (limiting the number of characters) and then allows the delegate, if any, to have its shot at the editing process. In the Cocoa world, it makes more sense to hook up a delegate to do this work, especially if this is a one-off control. It comes down to thinking of it as a text field which limits number of characters rather than a number-of-characters-limited text field. If you need this behavior in multiple places in your application, you can factor out the delegate behavior into a superclass and have your delegates derive from it, calling this method when necessary. What if the delegates are already subclassed? Since multiple inheritance is not an option, the code that limits the number of characters would have to be repeated in several places. On Jul 25, 2009, at 11:20 PM, Luke the Hiesterman wrote: If you simply called your new delegate something other than delegate - like myCustomClassDelegate or whatever then it wouldn't be convoluted. But overloading self.delegate is not a good idea at all. This custom text field is still a text field in every way. It simply performs some work between the editing done by super and the editing done by the delegate. There is no reason for any outside entity to want to refer to super.delegate. In fact, unless I'm wrong, I don't think it's even possible to retrieve super.delegate from the custom instance. My understanding is that super is not an object but merely a directive to the compiler instructing it where to start the search for a method implementation. Moreover, all delegate methods are implemented by the custom class and they all query the outside delegate as needed. Thus, as far as any clients of the custom class are concerned, a delegate of the custom instance is as true a delegate as the delegate of any non-subclassed UITextField. There is no way, as far as I can see, that an outside entity could ascertain that the delegate reported by calling -delegate is not the true delegate. Also, I think it would be confusing for a client of the custom class to have to set itself as a custom delegate when it's trying to do what it would normally do as a regular delegate. Moreover, what would prevent it from setting itself up as the true delegate? Given the choice of calling -setDelegate and -setCustomDelegate, what would one do? The way I'm doing this, everything is as transparent as possible. You call -setDelegate to set yourself up as the delegate just as you would if this text field was a regular UITextField, and when you call - delegate you get the correct object as well. The custom class is then a perfect replacement for a regular UITextField. Other than replacing [[UITextField alloc] init] with [[CustomTextField alloc] init], there are NO changes to client code anywhere. Can you give me an example of a situation where this might be a bad idea? I really can't see any. Wagner ___ 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: Multiple delegates Window
On Sat, Jul 25, 2009 at 4:55 PM, Gevikmac...@xs4all.nl wrote: I was wondering if it is possible to connect more than one delegate from the Window in IB. When I create a new Cocoa application in XCode, the Delegate_AppDelegate.m/h is created automatically. I would like to add a second object with specific functionality as a delegate object. Many delegate messages are also posted as notifications. Maybe you can register for the notification and handle it there. ___ 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: Multiple delegates Window
There is only one window outlet, so you can only hook up one object as the window's delegate. I am currently running into a similar issue with a text field delegate. See the discussion in the thread [iPhone] Why can't a UITextField be its own delegate? My solution, which has stirred some controversy, is to re-route the delegate internally so that I can achieve a measure of delegation chaining in such a way that, from the outside, it still looks like there is only one delegate. (The thread is actually about a possible bug in the iPhone SDK, but it has veered into a discussion of the pros and cons of my approach) On Jul 25, 2009, at 11:55 PM, Gevik wrote: I was wondering if it is possible to connect more than one delegate from the Window in IB. When I create a new Cocoa application in XCode, the Delegate_AppDelegate.m/h is created automatically. I would like to add a second object with specific functionality as a delegate object. How do I do this? 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: Multiple delegates Window
Correction... I meant to say There is only one DELEGATE outlet... not There is only one WINDOW outlet... ___ 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: I need a milder application badge (solution)
On Sat, Jul 25, 2009 at 12:15 PM, Jay Reynolds Freemanjay_reynolds_free...@mac.com wrote: I do not want to change the dockTile, and no public method of NSDockTile appears to change the dock icon in any case. I am indeed using -[NSApplication setApplicationIconImage:], my problem is creating a new image that has the correct areas transparent. Again, there is no such thing as a dock icon in the sense you're using the term. A dock tile is a thing that sits in the dock and draws an image. By default, this image is the one returned from -[NSApplication applicationIconImage]. If you want to customize this, you can hand it a view that does some drawing, and the dock tile will cease its own drawing behavior. When your app quits, your custom view gets removed, and since the dock tile no longer has an NSApplication to communicate with, it uses the image stored on disk. Notice there is no dock icon object to be handed around. The only icons that exist are the one in your app wrapper and the one returned by -[NSApplication applicationIconImage]. I'm also pretty sure you don't want to use -setApplicationIconImage:. That will cause all occasions of your app icon, including places that use +[NSImage imageNamed:] with an @NSApplicationIcon parameter, to display your customized icon. This is not the behavior your users will expect. I am sure I can do it; it's all just ones and zeros and I have access to all the bits. But I am not a graphics specialist and I am reluctant to become one. (And I have never used Photoshop or anything remotely like it.) I am just looking for a way to alter images dynamically, at run-time, that is as easy as putting up an offscreen window/view hierarchy and drawing into it. I would like to be able to use something like the capabilities of NSView for superimposing different things on my new image. I would like to work the problem at as high a level as I can. There is no such thing as modifying an image in Quartz. You're handed a buffer, you do your drawing, and the buffer is gone. You can't go back and muck with the image you drew into the buffer. It's like painting a wall: you can't lay down a layer of paint, paint some artistic design over that, and then go back and remove your first coat. The bits have already been mixed, as it were. All drawing on OS X happens within a window. This term includes not only what the user consider's a window, but also the menubar, each desktop icon, and each dock tile. The window has a bitmap called its backing store. When you tell Quartz Draw a red rectangle of this size, Quartz is dutifully changing bits in the backing store. If you tell Quartz Draw a red rectangle of this size at 50% alpha, Quartz has to mix 50% of the existing color in that affected area with 50% of your desired red color. As a final step, Quartz composites all the windows onscreen together into the framebuffer that your graphics card pulls from to draw the display. Views are an abstraction on top of this model. Each view has a -drawRect: method that it can use to draw into the current graphics context. The graphics context has to be associated with a window, and therefore a backing store. The view hierarchy presents a well-defined drawing order for the window's subviews, but it all boils down to the Painter's Algorithm, which is what I described above. --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: [iPhone] Why can't a UITextField be its own delegate?
Not if the delegates are already subclassed from classes not sharing a common ancestor. Even if they have a common ancestor, I might not have access to the source code for the ancestor so I might not be able to refactor the common code to that level. The end result is having to repeat code in several classes. On Jul 25, 2009, at 11:46 PM, Luke the Hiesterman wrote: That approach makes much more sense. Luke On Jul 25, 2009, at 2:44 PM, Kyle Sluder wrote: On Sat, Jul 25, 2009 at 1:14 PM, WTjrca...@gmail.com wrote: This particular text field needs to limit its number of characters to a given interval. Why should any other object have to deal with that problem when the field itself can take care of it? Still, it might be the case, though it also might not be the case, that another object wants to participate in the editing session. The flow of events here is as follows: the field takes care of its own business first (limiting the number of characters) and then allows the delegate, if any, to have its shot at the editing process. In the Cocoa world, it makes more sense to hook up a delegate to do this work, especially if this is a one-off control. It comes down to thinking of it as a text field which limits number of characters rather than a number-of-characters-limited text field. If you need this behavior in multiple places in your application, you can factor out the delegate behavior into a superclass and have your delegates derive from it, calling this method when necessary. --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: NSDictionary crash
Le 25 juil. 09 à 21:59, slasktrattena...@gmail.com a écrit : On Sat, Jul 25, 2009 at 9:39 PM, Kyle Sluderkyle.slu...@gmail.com wrote: As I mentioned, look at NSPropertyListSerialization. NSDictionary is a plist type and can be decoded from an NSData. OK, thanks. Also, is the NSData equivalent any safer than NSDictionary's? It's initWithContentsOfFile: method is documented to return An initialized object—which might be different than the original receiver—that contains the dictionary at path, or nil if there is a file error or if the contents of the file are an invalid representation of a dictionary. There's no mention of a potential crash. Should I file a bug? You can ensure the safety of the file before using NSData. You can't when using NSDictionary's convenience constructor. Sorry for being ignorant, but how do I ensure the safety of the file? I don't see anything about this in the NSData API. One issue that you will encounter, however, is that iTunes is incredibly picky about its file store. It will throw a tantrum if it can't write to its database. Hmm, OK. I suppose I could go for Apple Events when iTunes is running and only read the xml data when it's not. Shame about the speed, though. Ironically, I'm using the same approach but for the inverse reason. It's faster with Apple events than reading the whole XML File. ___ 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: Multiple delegates Window
On Jul 25, 2009, at 5:55 PM, Gevik wrote: I was wondering if it is possible to connect more than one delegate from the Window in IB. No, but you could make an object that forwards delegate messages to multiple other objects, and have that be the window delegate. --Andy ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: [iPhone] Why can't a UITextField be its own delegate?
On Sat, Jul 25, 2009 at 3:00 PM, WTjrca...@gmail.com wrote: What if the delegates are already subclassed? Since multiple inheritance is not an option, the code that limits the number of characters would have to be repeated in several places. You always have categories, but that's not necessarily a good idea. If you find yourself in this situation (class C needs behavior from both class B and class A), you can always collapse the class hierarchy and turn A and B into class AB, with options to configure its behavior. That's how we wind up with things like NSController on the desktop side, which can exist as an object controller or an entity controller. This custom text field is still a text field in every way. Then it should remain a UITextField. There is no reason for any outside entity to want to refer to super.delegate. In fact, unless I'm wrong, I don't think it's even possible to retrieve super.delegate from the custom instance. Ooh, I think we've found your bug. Internally, UITextField is going to use self.delegate to get its delegate, following the correct accessor behavior. You've gone and replaced -delegate to return self. But the delegate pattern says that messages which this object does not understand should be forwarded to the delegate. This means that a class with a delegate needs to implement -respondsToSelector: this way: - (BOOL)respondsToSelector:(SEL)aSelector { return [super respondsToSelector:aSelector] || [self.delegate respondsToSelector:aSelector]; } Since -delegate is going to return self, -respondsToSelector: is going to result in infinite recursion. So It's Never Safe To Make An Object Its Own Delegate. --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: [iPhone] Why can't a UITextField be its own delegate?
On Jul 26, 2009, at 12:23 AM, Kyle Sluder wrote: On Sat, Jul 25, 2009 at 3:00 PM, WTjrca...@gmail.com wrote: What if the delegates are already subclassed? Since multiple inheritance is not an option, the code that limits the number of characters would have to be repeated in several places. You always have categories, but that's not necessarily a good idea. True, but you can't add instance variables to categories and the code for limiting the number of characters (or a more general problem) needs some ivars. If you find yourself in this situation (class C needs behavior from both class B and class A), you can always collapse the class hierarchy and turn A and B into class AB, with options to configure its behavior. That's how we wind up with things like NSController on the desktop side, which can exist as an object controller or an entity controller. Now I'm the one who's going to say that's convoluted. :) This custom text field is still a text field in every way. Then it should remain a UITextField. There is no reason for any outside entity to want to refer to super.delegate. In fact, unless I'm wrong, I don't think it's even possible to retrieve super.delegate from the custom instance. Ooh, I think we've found your bug. Internally, UITextField is going to use self.delegate to get its delegate, following the correct accessor behavior. You've gone and replaced -delegate to return self. No. -delegate returns the outside delegate, not self. As I said, from the outside world, everything is business as usual. If you call - setDelegate: to set yourself up as the delegate, then you are what's returned by a call to -delegate. I might be mistaken but I think even internally UITextField would see the outside delegate when it calls self.delegate. self tells the runtime system to start the search at the bottom, which is CustomTextField, not UITextField. But the delegate pattern says that messages which this object does not understand should be forwarded to the delegate. This means that a class with a delegate needs to implement -respondsToSelector: this way: - (BOOL)respondsToSelector:(SEL)aSelector { return [super respondsToSelector:aSelector] || [self.delegate respondsToSelector:aSelector]; } Since -delegate is going to return self, -respondsToSelector: is going to result in infinite recursion. So It's Never Safe To Make An Object Its Own Delegate. You might be on to something here... I have to think about the above. Wagner ___ 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 tell an object to notify its KVOs that one of its properties needs to be re-cached...
On Jul 25, 2009, at 14:04, Steven Degutis wrote: When we have an object who has a property that's generated based on other properties, usually we implement the +keyPathsForValuesAffecting[PropertyName] class method. What I'm trying to do is basically the same thing for a property on my NSManagedObject, but traversing a relationship. My model is simple; I have two Entities, App and Version (I'm creating an appcast-generating app). There is a dynamic property - (NSString*) appcast; which is generated based on all the details of the app and its versions relationships. When the App's properties are changed, the -appcast string is re-cached, and all bindings are updated appropriately, simply because I implemented +keyPathsForValuesAffectingAppcast, as per the statement above. However, when any properties on any of a specific App's Versions (to- many relationship) change, the -appcast property is not generated appropriately. Is there a way to have this dynamic property re-cached any time certain (any) properties on its versions relationship are changed? So far, I've tried to include key paths such as versions.versionNumber in the NSSet returned from the aforementioned method, but that just throws an exception that the key versionNumber does not exist on NSSet. Yes, you can't run a key path through a collection property like that. Even if you could, it wouldn't be desirable, because it would mean that the number of objects being (automatically) observed could grow exponentially, in general, though in your case I'd imagine there's only a small number of version objects per app. I can think of three ways of proceeding (in increasing order of pain): 1. Observe the managed object context's NSManagedObjectContextObjectsDidChangeNotification, and invoke [app will/didChangeValueForKey: @appcast] pairs for each app affected by a change. 2. Force the versions property to change when a Version object changes. That is, override the Version property setters to do (say) self.app = self.app as well as the appropriate setPrimitiveValue: ... . 3. Have each app manually observe each property of each version in versions, and observe versions itself so you can add/remove the other observations as required. Or maybe I'm overlooking something obvious that's easier. ___ 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: [iPhone] Why can't a UITextField be its own delegate?
On Jul 25, 2009, at 3:23 PM, Kyle Sluder wrote: Internally, UITextField is going to use self.delegate to get its delegate, following the correct accessor behavior. You've gone and replaced -delegate to return self. But the delegate pattern says that messages which this object does not understand should be forwarded to the delegate. This means that a class with a delegate needs to implement -respondsToSelector: this way: - (BOOL)respondsToSelector:(SEL)aSelector { return [super respondsToSelector:aSelector] || [self.delegate respondsToSelector:aSelector]; } Where is this guaranteed by the delegate pattern? I've created a fair number of classes with delegates and never done this; it would be interesting to know that I've been doing it wrong for years ;). Since -delegate is going to return self, -respondsToSelector: is going to result in infinite recursion. So It's Never Safe To Make An Object Its Own Delegate. Even if it's safe, it's a bizarre way to do something, especially if you're already subclassing it...especially since delegates are mainly used to avoid subclassing. For the specific case of limiting text field input, why not just use an NSFormatter subclass, though? That's what I'd do in Cocoa (and this is the cocoa-dev list, after all). smime.p7s Description: S/MIME cryptographic signature ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: [iPhone] Why can't a UITextField be its own delegate?
On Jul 25, 2009, at 3:36 PM, WT jrca...@gmail.com wrote: No. -delegate returns the outside delegate, not self. As I said, from the outside world, everything is business as usual. If you call -setDelegate: to set yourself up as the delegate, then you are what's returned by a call to -delegate. If that were the case then your delegate insertion technique would be useless, since whenever UITextField wanted to ask it's delegate for something it would always get the external 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
The correct NSPredicate format for one-to-many relationship in Core Data
Hello, I have a managed object model entities A and B with one-to-many relationship. For this particular task, I want to retrieve all A objects which has a relation to B with a property matches to string. I had tried @ALL bObjects.bProperty MATCHES 'string', and it caused an objc_exception_throw in: [NSSQLGenerator generateSQLStatementForFetchRequest:ignoreInheritance:countOnly:] What seems to be the problem ? Anybody can advise me on the correct predicate format ? Jesse Armand (http://jessearmand.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: [iPhone] Why can't a UITextField be its own delegate?
On Jul 26, 2009, at 12:23 AM, Kyle Sluder wrote: There is no reason for any outside entity to want to refer to super.delegate. In fact, unless I'm wrong, I don't think it's even possible to retrieve super.delegate from the custom instance. Ooh, I think we've found your bug. I don't think so. Internally, UITextField is going to use self.delegate to get its delegate, following the correct accessor behavior. You've gone and replaced -delegate to return self. As I said earlier, -delegate returns the outside delegate, not self. But, in the sample application, there is no outside delegate so, yes, - delegate returns self. But this shouldn't be a problem because the custom text field implements ALL methods of the UITextFieldDelegate protocol. But the delegate pattern says that messages which this object does not understand should be forwarded to the delegate. Not a problem. See above. This means that a class with a delegate needs to implement -respondsToSelector: this way: - (BOOL)respondsToSelector:(SEL)aSelector { return [super respondsToSelector:aSelector] || [self.delegate respondsToSelector:aSelector]; } [super respondsToSelector:aSelector] is, according to the docs, identical to [self respondsToSelector:aSelector]. And since self.delegate, in the sample app, returns self, this is indeed an infinite loop. But, does UITextField implement -respondsToSelector: as above? Since -delegate is going to return self, -respondsToSelector: is going to result in infinite recursion. True. So, the question is, again: does UITextField implement - respondsToSelector: as above? Wagner ___ 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: [iPhone] Why can't a UITextField be its own delegate?
On Jul 26, 2009, at 12:41 AM, Adam R. Maxwell wrote: On Jul 25, 2009, at 3:23 PM, Kyle Sluder wrote: Internally, UITextField is going to use self.delegate to get its delegate, following the correct accessor behavior. You've gone and replaced -delegate to return self. But the delegate pattern says that messages which this object does not understand should be forwarded to the delegate. This means that a class with a delegate needs to implement -respondsToSelector: this way: - (BOOL)respondsToSelector:(SEL)aSelector { return [super respondsToSelector:aSelector] || [self.delegate respondsToSelector:aSelector]; } Where is this guaranteed by the delegate pattern? I've created a fair number of classes with delegates and never done this; it would be interesting to know that I've been doing it wrong for years ;). Good point! Since -delegate is going to return self, -respondsToSelector: is going to result in infinite recursion. So It's Never Safe To Make An Object Its Own Delegate. Even if it's safe, it's a bizarre way to do something, especially if you're already subclassing it...especially since delegates are mainly used to avoid subclassing. As I pointed out earlier, the common work that needs to be done consumes the delegate outlet. Thus, any extra work that would otherwise be done by a delegate requires an outlet for that outside delegate. I simply wire things up internally so that the work is chained while, to the outside world, it still looks as though there is only one delegate. For the specific case of limiting text field input, why not just use an NSFormatter subclass, though? That's what I'd do in Cocoa (and this is the cocoa-dev list, after all). Ok, that's an idea I hadn't thought of and worth exploring. Thanks for the suggestion. Wagner ___ 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: Multiple delegates Window
On Jul 25, 2009, at 6:21 PM, Andy Lee wrote: On Jul 25, 2009, at 5:55 PM, Gevik wrote: I was wondering if it is possible to connect more than one delegate from the Window in IB. No, but you could make an object that forwards delegate messages to multiple other objects, and have that be the window delegate. You could probably implement this quickly with an NSProxy, for example. But note that some window delegate methods have return values. You'd have to decide what your proxy object should return. If all you want is notifications, then Stephen's suggestion makes sense. --Andy ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: [iPhone] Why can't a UITextField be its own delegate?
On Jul 25, 2009, at 3:41 PM, Adam R. Maxwell amaxw...@mac.com wrote: Where is this guaranteed by the delegate pattern? I've created a fair number of classes with delegates and never done this; it would be interesting to know that I've been doing it wrong for years ;). You seem to be right; I can't find this in the documentation. Must be confusing it with another pattern. But the critical point is that if the object ever invokes - respondsToSelector: on self.delegate it will infinitely recurse. This is a very common pattern. One could override -respondsToSelector: to fix this issue, but then it would have to do some trickery to ensure it skips super's implementation. And that's just for this one known case. --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: Unit testing question
If you just starting out with Unit testing, I would suggest you picking up a good book covering the subject. For starters I would recommend every developer to read The pragmatic programmer (http://www.amazon.com/Pragmatic-Programmer-Journeyman-Master/dp/020161622X ) and then to complete the circle of knowledge a book completely covering the unit testing subject such as (http://www.amazon.com/Pragmatic-Software-Testing-Effective-Professional/dp/0470127902/ref=sr_1_5?ie=UTF8s=booksqid=124856sr=1-5 ) Please note that none of the books cover any specific language or testing framework. If you just are in a hurry trying to grab some new info and apply to to your project, could you please describe more in detail what you would like to accomplish and maybe I can get you started. Info like type of testing needed, is it a library or a UI based application, threading, data access etc. Message: 2 Date: Sat, 25 Jul 2009 12:09:13 -0700 From: Matt Neuburg m...@tidbits.com Subject: Re: Unit testing question To: cocoa-dev@lists.apple.com Message-ID: c690a669.4bdf4%m...@tidbits.com Content-Type: text/plain; charset=US-ASCII On Jul 25, 2009, at 1:17 AM, lorenzo7...@gmail.com wrote: I'd like to add unit testing to my app, but I'ma little bit unclear on the concept. I've looked at Apple's docs on the Sentest framework and had no trouble getting the sample project working, but I lose it when translating the concepts to my particular application. I've seen some sample projects around the net that use the Sentest framework, but the the unit tests are trivially simple, asserting that 1+1 = 2, for example. What I really need is a sample project of some complexity that uses real unit tests against the project. Can anyone help me out here? This is not exactly unit testing per se, but if you want to exercise your app thru its interface, you might want to consider GUI scripting. With GUI scripting you can both drive and read an application's interface through Apple events. One good way to implement a battery of GUI scripting tests is with rb-appscript. m. ___ 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: [iPhone] Why can't a UITextField be its own delegate?
On Jul 26, 2009, at 12:42 AM, Kyle Sluder wrote: On Jul 25, 2009, at 3:36 PM, WT jrca...@gmail.com wrote: No. -delegate returns the outside delegate, not self. As I said, from the outside world, everything is business as usual. If you call -setDelegate: to set yourself up as the delegate, then you are what's returned by a call to -delegate. If that were the case then your delegate insertion technique would be useless, since whenever UITextField wanted to ask it's delegate for something it would always get the external object. Hmm... I think you're right. Still, that has nothing to do with the freeze since the sample app has no outside delegates. Now, I agree that UITextField will run into an infinite loop (in the sample app) when calling -respondsToSelector on its delegate because it is its own delegate. However, why is it then that - textFieldShouldBeginEditing returns successfully and - textFieldDidBeginEditing executes but doesn't return? Both of them successfully print their method names: - (BOOL) textFieldShouldBeginEditing: (UITextField*) text_field { NSLog(@-textFieldShouldBeginEditing:); return YES; } - (void) textFieldDidBeginEditing: (UITextField*) text_field { NSLog(@-textFieldDidBeginEditing:); } It would seem that -respondsToSelector: is not being called at all. Wagner ___ 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: I need a milder application badge (solution)
On Jul 25, 2009, at 3:14 PM, Kyle Sluder provided a variety of extremely helpful and pertinent comments: I'm also pretty sure you don't want to use -setApplicationIconImage:. That will cause all occasions of your app icon, including places that use +[NSImage imageNamed:] with an @NSApplicationIcon parameter, to display your customized icon. This is not the behavior your users will expect. Kyle, I read you loud and clear, or at least I think I do, but the behavior you describe for the app icon image in the dock is not what I am seeing. I am running my application now, with my bitmap-hacking code in place, and it has passed the point where the modified NSImage has been passed to -setApplicationIconImage: . The icon in the dock has indeed changed to the modified version, but when I look at other places where I expect the unmodified icon to show up, I still see the unmodified icon. That includes all views of folders where the application is stored (those views having been opened or refreshed since starting the application), the window produced by my application's About menu item, and the Apple Recent Items menu, for example. The only appearance I am trying to alter is the appearance of the application icon that sits in the dock when the program is running, and that seems to be all that -setApplicationIconImage: is changing. (My own code doesn't happen to call [NSImage imageNamed:@NSApplicationIcon]. Perhaps there are library or framework routines that are calling it on my behalf, whose outputs I should review?) Furthermore, I only want this change to persist while the program is active. The change I am making is like the red circle with a number in it that sits on the Mail icon and shows how many new EMails you have. I would use the published interface to that feature, except that a bright red color is a bit too strident for my purposes. There is no such thing as modifying an image in Quartz. Maybe so, but you can certainly grab the bits you have drawn, using -[NSBitmapImageRep initWithFocusedViewRect:], and then add that instance of NSBitmapImageRep to a new instance of NSImage, using -[NSImage addRepresentation:], and then use the new instance of NSImage for whatever purpose you like. That is what I am doing, albeit with rather more hackery of the bitmap than I would wish. All drawing on OS X happens within a window ... If you tell Quartz Draw a red rectangle of this size at 50% alpha, Quartz has to mix 50% of the existing color in that affected area with 50% of your desired red color. Precisely! And what I am wishing for is a way to specify a window whose existing color is transparent, so that the bitmap created will in essence have (red, green, blue, alpha) = (0, 0, 0, 0), in locations not otherwise explicitly drawn. If such a window appeared on the visible part of the screen, there would clearly be problems -- there is no way to draw transparent with nothing behind it. But for setting up offscreen windows for the capture of bitmaps that include transparent areas, such a feature would be very useful, and I would like it to be at the window-and-view-hierarchy level of abstraction, because that is easier to use, particularly for ignorant beginners like me, than the compositing level that underlies it. If there really is no way to do this in the existing software, I will put in an enhancement request and we will see what happens. - jay_reynolds_free...@mac.com http://web.mac.com/jay_reynolds_freeman (personal web site) ___ 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: [iPhone] Why can't a UITextField be its own delegate?
On Jul 26, 2009, at 1:04 AM, WT wrote: Now, I agree that UITextField will run into an infinite loop (in the sample app) when calling -respondsToSelector on its delegate because it is its own delegate. However, why is it then that - textFieldShouldBeginEditing returns successfully and - textFieldDidBeginEditing executes but doesn't return? Both of them successfully print their method names: - (BOOL) textFieldShouldBeginEditing: (UITextField*) text_field { NSLog(@-textFieldShouldBeginEditing:); return YES; } - (void) textFieldDidBeginEditing: (UITextField*) text_field { NSLog(@-textFieldDidBeginEditing:); } It would seem that -respondsToSelector: is not being called at all. Actually, it is and I do get an infinite loop, thanks to - (BOOL) respondsToSelector: (SEL) selector { NSLog(@-respondsToSelector:); return [super respondsToSelector: selector]; } How do I get a string for the name of the method represented by the selector? Wagner ___ 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: I need a milder application badge (solution)
On Jul 25, 2009, at 4:04 PM, Jay Reynolds Freeman wrote: On Jul 25, 2009, at 3:14 PM, Kyle Sluder provided a variety of extremely helpful and pertinent comments: I'm also pretty sure you don't want to use - setApplicationIconImage:. That will cause all occasions of your app icon, including places that use +[NSImage imageNamed:] with an @NSApplicationIcon parameter, to display your customized icon. This is not the behavior your users will expect. Kyle, I read you loud and clear, or at least I think I do, but the behavior you describe for the app icon image in the dock is not what I am seeing. I am running my application now, with my bitmap-hacking code in place, and it has passed the point where the modified NSImage has been passed to -setApplicationIconImage: . The icon in the dock has indeed changed to the modified version, but when I look at other places where I expect the unmodified icon to show up, I still see the unmodified icon. You're seeing the documented behavior for setApplicationIconImage:, as I read TFM: This method sets the icon in the dock application tile. This method scales the image as necessary so that it fits in the dock tile. You can use this method to change your application icon while running. To restore your application’s original icon, you pass nil to this method. http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSApplication_Class/Reference/Reference.html smime.p7s Description: S/MIME cryptographic signature ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: [iPhone] Why can't a UITextField be its own delegate?
On Jul 25, 2009, at 3:41 PM, Adam R. Maxwell wrote: On Jul 25, 2009, at 3:23 PM, Kyle Sluder wrote: Internally, UITextField is going to use self.delegate to get its delegate, following the correct accessor behavior. You've gone and replaced -delegate to return self. But the delegate pattern says that messages which this object does not understand should be forwarded to the delegate. This means that a class with a delegate needs to implement -respondsToSelector: this way: - (BOOL)respondsToSelector:(SEL)aSelector { return [super respondsToSelector:aSelector] || [self.delegate respondsToSelector:aSelector]; } Where is this guaranteed by the delegate pattern? I've created a fair number of classes with delegates and never done this; it would be interesting to know that I've been doing it wrong for years ;). It's not guaranteed - it's just the right way to implement an optional delegate method. Luke ___ 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: [iPhone] Why can't a UITextField be its own delegate?
On Jul 25, 2009, at 4:04 PM, WT wrote: On Jul 26, 2009, at 12:42 AM, Kyle Sluder wrote: On Jul 25, 2009, at 3:36 PM, WT jrca...@gmail.com wrote: No. -delegate returns the outside delegate, not self. As I said, from the outside world, everything is business as usual. If you call -setDelegate: to set yourself up as the delegate, then you are what's returned by a call to -delegate. If that were the case then your delegate insertion technique would be useless, since whenever UITextField wanted to ask it's delegate for something it would always get the external object. Hmm... I think you're right. Still, that has nothing to do with the freeze since the sample app has no outside delegates. The reason for the freeze is UITextField implements a couple of the methods that it defines as delegate methods. The methods then end up calling themselves repeatedly when the delegate is self. This kind of thing was never intended to be supported. Also, as far as the overloading of self.delegate, I think you're failing to understand some things about objective-c. There's only one ivar in your class that holds the delegate. There's really no way to have 2 different objects there. Calling [self delegate] always goes to the same method no matter where it's called from. Luke ___ 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: [iPhone] Why can't a UITextField be its own delegate?
On Jul 25, 2009, at 5:02 PM, Luke the Hiesterman wrote: On Jul 25, 2009, at 3:41 PM, Adam R. Maxwell wrote: On Jul 25, 2009, at 3:23 PM, Kyle Sluder wrote: Internally, UITextField is going to use self.delegate to get its delegate, following the correct accessor behavior. You've gone and replaced -delegate to return self. But the delegate pattern says that messages which this object does not understand should be forwarded to the delegate. This means that a class with a delegate needs to implement -respondsToSelector: this way: - (BOOL)respondsToSelector:(SEL)aSelector { return [super respondsToSelector:aSelector] || [self.delegate respondsToSelector:aSelector]; } Where is this guaranteed by the delegate pattern? I've created a fair number of classes with delegates and never done this; it would be interesting to know that I've been doing it wrong for years ;). It's not guaranteed - it's just the right way to implement an optional delegate method. Who says it's the right way, though? I've never seen a delegate implemented that way, in documentation or sample code, and wouldn't you also have to implement forwarding code to keep this from breaking? Maybe I'm dense, but I don't see the point of doing this. smime.p7s Description: S/MIME cryptographic signature ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: I need a milder application badge (solution)
Jay Reynolds Freeman wrote: Precisely! And what I am wishing for is a way to specify a window whose existing color is transparent, so that the bitmap created will in essence have (red, green, blue, alpha) = (0, 0, 0, 0), in locations not otherwise explicitly drawn. If such a window appeared on the visible part of the screen, there would clearly be problems -- there is no way to draw transparent with nothing behind it. But for setting up offscreen windows for the capture of bitmaps that include transparent areas, such a feature would be very useful, and I would like it to be at the window-and-view-hierarchy level of abstraction, because that is easier to use, particularly for ignorant beginners like me, than the compositing level that underlies it. Maybe you're having trouble with transparency (i.e. alpha) because some of your view hierarchy is opaque. Another possibility is that somehow the backing-store image you're drawing into doesn't support alpha, so any alpha actually rendered into its pixels is lost, leaving only a solid black color. Or perhaps you're not initializing the backing-store image with the correct color that has alpha=0. You should be able to paint a solid (i.e. opaque) rectangle of rgba=0:0:0:0 and have it set every pixel in the backing-store to that value. Subsequent elements drawn on top of that initial base color would then combine using the given compositing operation and the source and dest images. http://en.wikipedia.org/wiki/Alpha_compositing I also don't think you've posted the actual working code, so you could be making a simple mistake in how the backing store is initialized, how it's prepared for rendering, what compositing operation is used, or something like that. If it's too complicated to post your current code, you should make a well-isolated example that demonstrates the problem, and post the URL for it (or if small enough, post the source). Without seeing actual code, I don't think much progress is going to be made. -- GG ___ 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: [iPhone] Why can't a UITextField be its own delegate?
On Jul 25, 2009, at 5:32 PM, Adam R. Maxwell wrote: On Jul 25, 2009, at 5:02 PM, Luke the Hiesterman wrote: On Jul 25, 2009, at 3:41 PM, Adam R. Maxwell wrote: On Jul 25, 2009, at 3:23 PM, Kyle Sluder wrote: Internally, UITextField is going to use self.delegate to get its delegate, following the correct accessor behavior. You've gone and replaced -delegate to return self. But the delegate pattern says that messages which this object does not understand should be forwarded to the delegate. This means that a class with a delegate needs to implement -respondsToSelector: this way: - (BOOL)respondsToSelector:(SEL)aSelector { return [super respondsToSelector:aSelector] || [self.delegate respondsToSelector:aSelector]; } Where is this guaranteed by the delegate pattern? I've created a fair number of classes with delegates and never done this; it would be interesting to know that I've been doing it wrong for years ;). It's not guaranteed - it's just the right way to implement an optional delegate method. Who says it's the right way, though? I've never seen a delegate implemented that way, in documentation or sample code, and wouldn't you also have to implement forwarding code to keep this from breaking? Maybe I'm dense, but I don't see the point of doing this. I read the code too quickly. I just thought it was the standard if ([delegate respondsToSelector:]) [delegate doSomething]; paradigm. I retract my statement. That is definitely not a standard of the delegation pattern. Luke ___ 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: [iPhone] Why can't a UITextField be its own delegate?
On Jul 26, 2009, at 1:18 AM, WT wrote: On Jul 26, 2009, at 1:04 AM, WT wrote: Now, I agree that UITextField will run into an infinite loop (in the sample app) when calling -respondsToSelector on its delegate because it is its own delegate. However, why is it then that - textFieldShouldBeginEditing returns successfully and - textFieldDidBeginEditing executes but doesn't return? Both of them successfully print their method names: - (BOOL) textFieldShouldBeginEditing: (UITextField*) text_field { NSLog(@-textFieldShouldBeginEditing:); return YES; } - (void) textFieldDidBeginEditing: (UITextField*) text_field { NSLog(@-textFieldDidBeginEditing:); } It would seem that -respondsToSelector: is not being called at all. Actually, it is and I do get an infinite loop, thanks to - (BOOL) respondsToSelector: (SEL) selector { NSLog(@-respondsToSelector:); return [super respondsToSelector: selector]; } How do I get a string for the name of the method represented by the selector? I'm beginning to understand the intricacies of this problem... First, since I don't know how to get the name of a method (as a string) from its selector, I'm simply outputting the selector itself, which is an address. Now, consider this as the subclass implementation: #import CustomTextField.h @implementation CustomTextField - (void) awakeFromNib { super.delegate = self; super.text = @Hello world; NSLog(@awakeFromNib called - delegate set to self); } // = = = = = // - (BOOL) textField: (UITextField*) text_field shouldChangeCharactersInRange: (NSRange) range replacementString: (NSString*) string { NSLog(@-textField: shouldChangeCharactersInRange: replacementString: %p, @selector(textField: shouldChangeCharactersInRange: replacementString:)); return YES; } // = = = = = // - (BOOL) textFieldShouldBeginEditing: (UITextField*) text_field { NSLog(@-textFieldShouldBeginEditing: %p, @selector(textFieldShouldBeginEditing:)); return YES; } // = = = = = // - (void) textFieldDidBeginEditing: (UITextField*) text_field { NSLog(@-textFieldDidBeginEditing: %p, @selector(textFieldDidBeginEditing:)); } // = = = = = // - (BOOL) textFieldShouldEndEditing: (UITextField*) text_field { NSLog(@-textFieldShouldEndEditing: %p, @selector(textFieldShouldEndEditing:)); return YES; } // = = = = = // - (void) textFieldDidEndEditing: (UITextField*) text_field { NSLog(@-textFieldDidEndEditing: %p, @selector(textFieldDidEndEditing:)); } // = = = = = // - (BOOL) textFieldShouldClear: (UITextField*) text_field { NSLog(@-textFieldShouldClear: %p, @selector(textFieldShouldClear:)); return YES; } // = = = = = // - (BOOL) textFieldShouldReturn: (UITextField*) text_field { NSLog(@-textFieldShouldReturn: %p, @selector(textFieldShouldReturn:)); [self resignFirstResponder]; return YES; } // = = = = = // - (BOOL) respondsToSelector: (SEL) selector { NSLog(@-respondsToSelector: %p, selector); if (selector == @selector(textField:shouldChangeCharactersInRange:replacementString:) || selector == @selector(textFieldShouldBeginEditing:) || selector == @selector(textFieldDidBeginEditing:) || selector == @selector(textFieldShouldEndEditing:) || selector == @selector(textFieldDidEndEditing:) || selector == @selector(textFieldShouldClear:) || selector == @selector(textFieldShouldReturn:)) { return YES; } else { return [UITextField instancesRespondToSelector: selector]; } } // = = = = = // @end This still causes an infinite loop, with the result being something like this: -respondsToSelector: 0x93147998 -respondsToSelector: 0x9316a1b4 -respondsToSelector: 0x931bf364 -respondsToSelector: 0x931389bc -respondsToSelector: 0x93142b98 -respondsToSelector: 0x931d30c4 -respondsToSelector: 0x93167564 -respondsToSelector: 0x319b8c98 -respondsToSelector: 0x319cc41a -respondsToSelector: 0x319f4af4 awakeFromNib called - delegate set to self -respondsToSelector: 0x319b5a68 -textFieldShouldBeginEditing: 0x319b5a68 -respondsToSelector: 0x319aa222 -respondsToSelector: 0x319aa124 -respondsToSelector: 0x319aa100 -respondsToSelector: 0x319aa387
Re: [iPhone] Why can't a UITextField be its own delegate?
I've told you twice now that the problem is UITextField implements selectors that it also uses as delegate calls. The answer to the question can I make delegate == self on UITextField is a definite NO. Luke On Jul 25, 2009, at 5:35 PM, WT wrote: On Jul 26, 2009, at 1:18 AM, WT wrote: On Jul 26, 2009, at 1:04 AM, WT wrote: Now, I agree that UITextField will run into an infinite loop (in the sample app) when calling -respondsToSelector on its delegate because it is its own delegate. However, why is it then that - textFieldShouldBeginEditing returns successfully and - textFieldDidBeginEditing executes but doesn't return? Both of them successfully print their method names: - (BOOL) textFieldShouldBeginEditing: (UITextField*) text_field { NSLog(@-textFieldShouldBeginEditing:); return YES; } - (void) textFieldDidBeginEditing: (UITextField*) text_field { NSLog(@-textFieldDidBeginEditing:); } It would seem that -respondsToSelector: is not being called at all. Actually, it is and I do get an infinite loop, thanks to - (BOOL) respondsToSelector: (SEL) selector { NSLog(@-respondsToSelector:); return [super respondsToSelector: selector]; } How do I get a string for the name of the method represented by the selector? I'm beginning to understand the intricacies of this problem... First, since I don't know how to get the name of a method (as a string) from its selector, I'm simply outputting the selector itself, which is an address. Now, consider this as the subclass implementation: #import CustomTextField.h @implementation CustomTextField - (void) awakeFromNib { super.delegate = self; super.text = @Hello world; NSLog(@awakeFromNib called - delegate set to self); } // = = = = = = === // - (BOOL) textField: (UITextField*) text_field shouldChangeCharactersInRange: (NSRange) range replacementString: (NSString*) string { NSLog(@-textField: shouldChangeCharactersInRange: replacementString: %p, @selector(textField: shouldChangeCharactersInRange: replacementString:)); return YES; } // = = = = = = === // - (BOOL) textFieldShouldBeginEditing: (UITextField*) text_field { NSLog(@-textFieldShouldBeginEditing: %p, @selector(textFieldShouldBeginEditing:)); return YES; } // = = = = = = === // - (void) textFieldDidBeginEditing: (UITextField*) text_field { NSLog(@-textFieldDidBeginEditing: %p, @selector(textFieldDidBeginEditing:)); } // = = = = = = === // - (BOOL) textFieldShouldEndEditing: (UITextField*) text_field { NSLog(@-textFieldShouldEndEditing: %p, @selector(textFieldShouldEndEditing:)); return YES; } // = = = = = = === // - (void) textFieldDidEndEditing: (UITextField*) text_field { NSLog(@-textFieldDidEndEditing: %p, @selector(textFieldDidEndEditing:)); } // = = = = = = === // - (BOOL) textFieldShouldClear: (UITextField*) text_field { NSLog(@-textFieldShouldClear: %p, @selector(textFieldShouldClear:)); return YES; } // = = = = = = === // - (BOOL) textFieldShouldReturn: (UITextField*) text_field { NSLog(@-textFieldShouldReturn: %p, @selector(textFieldShouldReturn:)); [self resignFirstResponder]; return YES; } // = = = = = = === // - (BOOL) respondsToSelector: (SEL) selector { NSLog(@-respondsToSelector: %p, selector); if (selector == @selector (textField:shouldChangeCharactersInRange:replacementString:) || selector == @selector(textFieldShouldBeginEditing:) || selector == @selector(textFieldDidBeginEditing:) || selector == @selector(textFieldShouldEndEditing:) || selector == @selector(textFieldDidEndEditing:) || selector == @selector(textFieldShouldClear:) || selector == @selector(textFieldShouldReturn:)) { return YES; } else { return [UITextField instancesRespondToSelector: selector]; } } // = = = = = = === // @end This still causes an infinite loop, with the result being something like this: -respondsToSelector: 0x93147998 -respondsToSelector: 0x9316a1b4 -respondsToSelector: 0x931bf364 -respondsToSelector: 0x931389bc -respondsToSelector: 0x93142b98 -respondsToSelector: 0x931d30c4 -respondsToSelector: 0x93167564 -respondsToSelector: 0x319b8c98 -respondsToSelector: 0x319cc41a -respondsToSelector:
Re: [iPhone] Why can't a UITextField be its own delegate?
On Jul 25, 2009, at 5:35 PM, WT wrote: First, since I don't know how to get the name of a method (as a string) from its selector, Did you miss NSStringFromSelector() and sel_getName()? smime.p7s Description: S/MIME cryptographic signature ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: [iPhone] Why can't a UITextField be its own delegate?
On Jul 26, 2009, at 2:42 AM, Luke the Hiesterman wrote: I've told you twice now that the problem is UITextField implements selectors that it also uses as delegate calls. By my count, you only did that once, and I only read it after I sent my last message. In any case, forgive me for being slow and trying to understand things in detail in my own ways. This is still a learning experience for me. ___ 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: [iPhone] Why can't a UITextField be its own delegate?
On Jul 26, 2009, at 2:42 AM, Adam R. Maxwell wrote: On Jul 25, 2009, at 5:35 PM, WT wrote: First, since I don't know how to get the name of a method (as a string) from its selector, Did you miss NSStringFromSelector() and sel_getName()? I did, even though I looked at both the NSString and NSObject documentation. Thanks! ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: [iPhone] Why can't a UITextField be its own delegate?
On Sat, Jul 25, 2009 at 5:35 PM, Luke the Hiestermanluket...@apple.com wrote: I read the code too quickly. I just thought it was the standard if ([delegate respondsToSelector:]) [delegate doSomething]; paradigm. I retract my statement. That is definitely not a standard of the delegation pattern. Nothing like being right for the wrong reasons. :P --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: I need a milder application badge (solution)
On Sat, Jul 25, 2009 at 4:04 PM, Jay Reynolds Freemanjay_reynolds_free...@mac.com wrote: Kyle, I read you loud and clear, or at least I think I do, but the behavior you describe for the app icon image in the dock is not what I am seeing. I am running my application now, with my bitmap-hacking code in place, and it has passed the point where the modified NSImage has been passed to -setApplicationIconImage: . The icon in the dock has indeed changed to the modified version, but when I look at other places where I expect the unmodified icon to show up, I still see the unmodified icon. That includes all views of folders where the application is stored (those views having been opened or refreshed since starting the application), the window produced by my application's About menu item, and the Apple Recent Items menu, for example. As far as the Finder or Recent Items are concerned, they are always going to get the icon from the bundle, never from a running application. So I wouldn't expect them to change. I would, however, expect your About panel's icon to change. Though since it doesn't, it shows that I was incorrect. The only appearance I am trying to alter is the appearance of the application icon that sits in the dock when the program is running, and that seems to be all that -setApplicationIconImage: is changing. (My own code doesn't happen to call [NSImage imageNamed:@NSApplicationIcon]. Perhaps there are library or framework routines that are calling it on my behalf, whose outputs I should review?) The default About panel does, I believe. As does NSAlert (which then does its own badging on top of that). Furthermore, I only want this change to persist while the program is active. The change I am making is like the red circle with a number in it that sits on the Mail icon and shows how many new EMails you have. I would use the published interface to that feature, except that a bright red color is a bit too strident for my purposes. The way I would do this would be to use an NSImage view as a custom dock tile view, and have that view display an image I draw myself. This is because of what I assumed -setApplicationIconImage: would imply for users of +[NSImage imageNamed:]. You have since demonstrated me wrong on this second point. There is no such thing as modifying an image in Quartz. Maybe so, but you can certainly grab the bits you have drawn, using -[NSBitmapImageRep initWithFocusedViewRect:], and then add that instance of NSBitmapImageRep to a new instance of NSImage, using -[NSImage addRepresentation:], and then use the new instance of NSImage for whatever purpose you like. That is what I am doing, albeit with rather more hackery of the bitmap than I would wish. What I mean is that you can't draw some stuff and change what you drew later. You are always drawing on a fresh canvas. What you want to do is take an existing bitmap image, draw it into a graphics context, and draw your custom badge on top of it in that same graphics context (a process known as composition). This writes the pixel data out to the graphics context's backing bitmap image, which you turn around and set as your application's image. I was suggesting instead to add a custom view to the dock tile and perform the same process in the graphics context attached to that view. My motivation was to avoid the problems I believed were associated with -setApplicationIconImage:, but even though those are moot you still have the benefit of the view having done all of the graphics context setup for you. If you want to redraw the icon, call -setNeedsDisplay on it, just like any other NSView. Within -drawRect:, you can start with the image returned by +[NSImage imageNamed:@NSApplicationIcon], draw that into the view's graphics context, and draw your badge atop it. Or you can do all of this in an offscreen graphics context and use that offscreen context's bitmap image representation to create an NSImage which you pass to an NSImageView that is the custom view of your dock tile. Maybe now it makes more sense? --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: I need a milder application badge (solution)
Jay: I hope I am on the mark here with what you are trying to achieve I have just constructed a rather tiny app that displays a custom image in the Dock. This custom view is shown in the dock for the app itself when running (not just when minimized). The app icon is *not* shown because I have set a custom content view for the dock tile (nor would any badge be displayed, if set). The custom view is a class named DockTileView. When the app starts up, I create an instance of this class, and set it as the dockTile's contentView: DockTileView *myDockTileView = [[[DockTileView alloc] init] autorelease]; [[NSApp dockTile] setContentView: myDockTileView]; [[NSApp dockTile] display]; // cause the dock tile have the view draw itself The DockTileView is a trivial subclass of NSView: @interface DockTileView : NSView { } @end For this proof-of-concept app, the DockTileView just displays some text in the overridden -drawRect method: @implementation DockTileView - (void) drawRect:(NSRect)rect { NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys: [NSColor orangeColor], NSForegroundColorAttributeName, [NSFont systemFontOfSize:32], NSFontAttributeName, nil]; NSString *text = @Custom\nDock\nTile; NSMutableAttributedString *as = [[NSMutableAttributedString alloc] initWithString:text attributes:attributes]; [as drawInRect:rect]; } @end Of course, you can have your custom view draw whatever you'd like (in a 128 x 128 frame). If the appearance of the view needs to change due to underlying changes in teh state of your app, just issue the -display message to the dockTile: [NSApp dockTile] display]; and the contentView object's -drawRect will be called. ___ 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: NSDictionary crash
Why use Core Foundation? How about (written in Mail): - (NSDictionary *)dictionaryFromPropertyListFile:(NSString *)path error:(NSError **)outError { NSData *data = [NSData dataWithContentsOfFile:path options:NULL error:outError]; if (!data) return nil; NSString *errorString; NSDictionary *plist = [NSPropertyListSerialization propertyListFromData:data mutabilityOption:NSPropertyListImmutable format:NULL errorDescription:errorString]; if (!plist) { NSDictionary *info = [NSDictionary dictionaryWithObject:errorString forKey:NSLocalizedDescriptionKey]; *outError = [NSError errorWithDomain:@MyAppDomain code:-1 userInfo:info]; return nil; } return plist; } If there is a read error, the NSData method should be robust enough to catch it and just return a nil object. If the data is truncated, modified, or corrupted during the read, NSPropertyListSerialization should detect it and return nil. If you are really concerned, wrap it all up in a @try/@catch. Call it, if it fails, wait a couple seconds and try again. If it continues to fail for 2 to 4 attempts, give up and report an error to the user. Also, it should be faster to just read the content of the file into an NSData than to open the file, parse the contents into a plist, then close the file (assuming that is what your other approaches are doing.) Also also, I suggest a quick-and-dirty test. Write a simple command line tool that calls this method repeatedly as fast as possible and logs all errors. Start it up and modify your iTunes library to see if you can induce any failure points. Or use ScriptingBridge. Regards, Aaron On Jul 25, 2009, at 4:53 PM, slasktrattena...@gmail.com wrote: On Sat, Jul 25, 2009 at 10:21 PM, Kyle Sluderkyle.slu...@gmail.com wrote: Also not a safe option; other Apple apps can access the XML file, includeing CoreServices (for the media picker in the Open panel). Unfortunately we don't know how they do it and therefore can't be guaranteed that they won't also break if you have a lock on the database file. Thanks for the heads up. I'm afraid the end users would be upset if the app required iTunes to be running all of a sudden, though. So I'll try with the Core Foundation methods for now (without locking the file). Hopefully it won't result in a crash if the file is modified while read, just a NULL pointer or invalid data (which is fine considering how often the data is read, I'll just rely on the last valid object). CFPropertyListRef CreateMyPropertyListFromFile( CFURLRef fileURL ) { CFPropertyListRef propertyList; CFStringRef errorString; CFDataRef resourceData; Boolean status; SInt32errorCode; // Read the XML file. status = CFURLCreateDataAndPropertiesFromResource( kCFAllocatorDefault, fileURL, resourceData,// place to put file data NULL, NULL, errorCode); // Reconstitute the dictionary using the XML data. propertyList = CFPropertyListCreateFromXMLData( kCFAllocatorDefault, resourceData, kCFPropertyListImmutable, errorString); if (resourceData) { CFRelease( resourceData ); } else { CFRelease( errorString ); } return propertyList; } ___ 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/aaron.burghardt%2Bcocoa-dev%40gmail.com This email sent to aaron.burghardt+cocoa-...@gmail.com smime.p7s Description: S/MIME cryptographic signature ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: [iPhone] Why can't a UITextField be its own delegate?
WT wrote: It seems I'll have to opt for having a regular UITextField and a custom class whose sole purpose is to provide a delegate that does the common work. As Kyle suggested, I may need to make that a superclass and derive additional delegates to perform extra work after the common task. As previously noted, you could also give the common-task delegate its own delegate. Then you get the advantages of delegation, it's just one level away from the UITextField's direct delegate. More generally, you could implement the Chain Of Responsibility pattern in the UITextField's direct delegate (the principal delegate), so any number of other secondary delegates could contribute to the overall task, in chain-priority order, and according to which selectors a secondary delegate implements. Since any secondary delegate could also be the principal of its own chain, you have the potential for a tree of delegates. -- GG ___ 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: NSScrollView Not Updating
On Sat, Jul 25, 2009 at 7:30 PM, Pierce Freemanpiercefreema...@comcast.net wrote: I am drawing elements dynamically to the screen, and attempting to put them in a NSScrollView. However, when I add them to the view inside the NSScrollView, it doesn't seem as if the scroll view knows that there is more contents. The elements simply go off of the top of the window, and it doesn't show any scroll bars which tells me that it doesn't think that there is any more elements. Could anyone tell me why this is happening, because I just can't figure it out. You need to post your code. It sounds like you've overridden -drawRect: to draw custom contents. The view's frame determines how the scroll view behaves; if you're just drawing all over the place in -drawRect: without properly calling -setFrame:, you need to stop that. --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: NSScrollView Not Updating
You need to post your code. I'll put my main code at the end of this email. It sounds like you've overridden -drawRect: to draw custom contents. The view's frame determines how the scroll view behaves; if you're just drawing all over the place in -drawRect: without properly calling -setFrame:, you need to stop that. I'm not quite sure if I'm over riding -drawRect:, but it's possible that I have. Hopefully my code will see if I have. AppController.m @interface AppController : NSObject { IBOutlet NSView *subView; IBOutlet NSScrollView *mainView; } @end AppController.h for (NSInteger i = 0; i 100; i++) { NSRect location = NSMakeRect(50, (i*120 + (i+9)*10), 400, 22); NSTextField *text1 = [[NSTextField alloc] initWithFrame:location]; [subView addSubview:text1]; [subView setAutoresizesSubviews:YES]; } ___ 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: NSScrollView Not Updating
On Sat, Jul 25, 2009 at 7:59 PM, Pierce Freemanpiercefreema...@comcast.net wrote: I'm not quite sure if I'm over riding -drawRect:, but it's possible that I have. Hopefully my code will see if I have. If you can't answer this question, you need to cover some basic fundamentals. Did you override -drawRect: is a very simple question that you can answer by simply looking at what code you've written. If you have written a subclass of NSView and implemented the -drawRect: method, and this is the view you're asking about, the answer is yes. Otherwise, it is no. [subView addSubview:text1]; When you add a subview to a superview, it doesn't resize the superview. NSScrollView has no idea about the contents of its document view's subviews, it only cares about its document view's size. Since it never changes, there's nothing for it to scroll. I recommend first going over some Cocoa fundamentals again. Then move on to the View Programming Guide. --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: I need a milder application badge (solution)
On 26/07/2009, at 11:16 AM, Stuart Malin wrote: Of course, you can have your custom view draw whatever you'd like (in a 128 x 128 frame). If the appearance of the view needs to change due to underlying changes in teh state of your app, just issue the -display message to the dockTile: [NSApp dockTile] display]; and the contentView object's -drawRect will be called. Stuart's technique is the correct one. You can easily draw the application icon with a badge in the -drawRect: method of your custom DockTile view: - (void)drawRect:(NSRect)rect { NSRect bounds = [self bounds]; //draw the icon NSImage* icon = [NSImage imageNamed:@NSApplicationIcon]; [icon setSize:bounds.size]; [icon drawAtPoint:NSZeroPoint fromRect:NSZeroRect operation:NSCompositeCopy fraction:1.0]; //draw your badge //badge drawing calls here } I do this myself in one of my apps and it works perfectly. -- 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