[SOLVED] Re: death in dealloc
Spot on, Steven. My memory management was faulty. My object had been instantiating another object via alloc that it kept a reference to in an iVar, and my (outer) object released that instantiated (inner) object in its -dealloc method. I refactored the code, and changed the way I acquire the (inner) object to use a class factory method, which returned an autoreleased instance. Of course, with this change, the reference to the (inner) object should no longer be held by an iVar, and so I have now changed that as well. On Mar 13, 2010, at 4:46 PM, Steven Degutis wrote: This is almost always caused by releasing an object earlier than you expected to, and then trying to release it again later (similar to double free). Look around in your class's code for a place where you autorelease an ivar, but don't add it to a collection, or where you release an ivar but don't set it to nil afterwards. -Steven On Sat, Mar 13, 2010 at 12:53 PM, Stuart Malin stu...@zhameesha.com wrote: I have some code that is throwing EXC_BAD_ACCESS. It does so when an object is deallocating, in its -dealloc method on a call to [super dealloc]. The object's class's superclass is NSObject. Here's the (relevant part of the) stack trace: #0 0x7fff872e016d in _class_hasCxxStructorsNoSuper #1 0x7fff872e0741 in object_cxxDestructFromClass #2 0x7fff872e60f8 in objc_destructInstance #3 0x7fff872e06f5 in _internal_object_dispose #4 0x7fff83e0279a in -[NSObject(NSObject) dealloc] #5 0x10007b18e in -[ZPOauthParams dealloc] at ZPOauthParams.m:57 I know I must have blown something, but I have no idea what I could have done to cause this sort of problem. If anyone has seen something like this before, please let me in what direction I should look for the problem. TIA. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
death in dealloc
I have some code that is throwing EXC_BAD_ACCESS. It does so when an object is deallocating, in its -dealloc method on a call to [super dealloc]. The object's class's superclass is NSObject. Here's the (relevant part of the) stack trace: #0 0x7fff872e016d in _class_hasCxxStructorsNoSuper #1 0x7fff872e0741 in object_cxxDestructFromClass #2 0x7fff872e60f8 in objc_destructInstance #3 0x7fff872e06f5 in _internal_object_dispose #4 0x7fff83e0279a in -[NSObject(NSObject) dealloc] #5 0x10007b18e in -[ZPOauthParams dealloc] at ZPOauthParams.m:57 I know I must have blown something, but I have no idea what I could have done to cause this sort of problem. If anyone has seen something like this before, please let me in what direction I should look for the problem. TIA. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
NSURLConnection Asynchronous vs. Synchronous Asymmetry
I haven't been able to find any documentation or relevant Web results regarding a situation I'm experiencing: I get different results for the same identical NSURLRequest when I execute the request using NSURLConnection's +sendSynchronousRequest versus when I execute using asynchronously by allocating an NSURLConnection's instance and calling -start on it. The particular request results in an HTTP 401 response (Not Authorized). When I execute asynchronously: 1a) -connection:didReceiveResponse: is invoked and supplies an NSHTTPURLResponse object 1b) the NSHTTPURLResponse object reports the HTTP result of 401 vis -statusCode. 2) -connection:didReceiveData: does receive data 3) -connection:didFailWithError is NOT invoked. When I execute synchronously with -sendSynchronousRequest:returningResponse:error: 1) the method does return the same data as the async 2) but: no response is returned 3) and: an NSError is returned, with the code of -1012 (which is NSURLErrorUserCancelledAuthentication as defined in NSURL.h) I expected the sendSynchronousRequest approach to return an NSHTTPURLResponse object without an error because, according to the docs, the synchronous method is built on top of the asynchronous methods. The asymmetry of the response is a unsettling as I'm trying to have my code work either with synchronous or asynchronous, but having to interpret results differently is making this a nuisance (especially mapping NSURL error codes back to HTTP status codes). Do I have unreasonable expectations? incorrect understanding? or should I be getting similar/identical results, and so look for a bug? Thanks for any advise... ___ 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: Proper way to initialize application support file
On Feb 18, 2010, at 12:30 AM, Paul Johnson wrote: I see the data I get from the internet as not in the strictest sense 'necessary' for the program to run, just that it would be unable to do very much without it. So using my loose definition, the Application Support folder would be the place to create my data file. This does not to me sound like a loose definition, and in my opinion this is exactly the kind of circumstance in which you should use the Application Support folder. If that data is specific to a user, then put it in ~/Application Support/appInfo. You can (and should) get the path for such directories from NSPathUtilities: For the system's Application Folder: NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSSystemDomainMask, YES); s = [paths objectAtIndex:0]; For the user's Application Folder: NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES); s = [paths objectAtIndex:0]; NSSearchPathForDirectoriesInDomains is described in Foundation Functions Reference. Values for the parameters (NSSearchPathDirectory and NSSearchPathDomainMask) are described in the Foundation Data Types Reference. Or just look at the enums declared in NSPathUtilities.h ___ 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
Guidance on use of Application Support folder
The recent post regarding Creating an Application Support folder http://lists.apple.com/archives/cocoa-dev/2010/Feb/msg00618.html made me think about that folder. My understanding is that this folder is to be used for information generically usable by the application, but not specific to a given user. I am building an app that needs to store per-user data that is not document specific. I have created a folder under ~/Library for this, and am not using ~/Library/Application Support. Is there guidance from Apple on where such per-user, non-document-specific data is supposed to be stored?___ 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: Guidance on use of Application Support folder
I sorta would agree, Jens, and certainly many apps do put user-specific files here, but the Apple docs specifically say this is NOT how the Application Support folder should be used. ~~~ A support file is any type of file that supports the application but is not required for the application to run. Document templates and sample files are simple examples of support files. However, you might store more application-bound information, such as custom configurations or preset data files for your application’s workspace. In these instances, the information is intrinsically tied to a specific application (as opposed to the user’s data) but is not essential for the application to run. http://developer.apple.com/documentation/MacOSX/Conceptual/BPFileSystem/Articles/WhereToPutFiles.html ~~~ In the File System Overview, is this: Table 1 Subdirectories of the Library directory Subdirectory Directory contents Application Support Contains application-specific data and support files such as third-party plug-ins, helper applications, templates, and extra resources that are used by the application but not required for it to operate. This directory should never contain any kind of user data. By convention, all of these items should be put in a subdirectory named after the application. For example, third-party resources for the application MyApp would go in Application Support/MyApp/. Note that required resources should go inside the application bundle itself. http://developer.apple.com/mac/library/documentation/MacOSX/Conceptual/BPFileSystem/Articles/LibraryDirectory.html#//apple_ref/doc/uid/20002282-BAJHCHJI Note the line: This directory should never contain any kind of user data. ~~~ There is some discussion of relevance here: http://www.cocoadev.com/index.pl?ApplicationSupportFolder On Feb 12, 2010, at 11:13 AM, Jens Alfke wrote: On Feb 12, 2010, at 8:05 AM, Stuart Malin wrote: I am building an app that needs to store per-user data that is not document specific. I have created a folder under ~/Library for this, and am not using ~/Library/Application Support. Is there guidance from Apple on where such per-user, non-document-specific data is supposed to be stored? I would say that's what Application Support is for. There are apps that create their own direct subfolders of ~/Library, but I think that's messy. —Jens ___ 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
Determining the name of a method's caller
I have tried to search for a technique to do this, but perhaps my searching skills are deficient. What I want to do is be able to write an NSLog() call in a method that emits information about the method that invoked the present method. This would serve me in debugging without needing to run gdb and put a break on the target method. I have run across content on the Web that suggests that the Google Toolbox for Mac has some such capability in GTMStackTrace, but while I did find GTMStackTrace.h, I didn't locate the implementation (.m) file. I'm wondering if this will be hard to do because of the need to access registers and the stack. If so, perhaps there is some C (or even assembler?) code that I can use as guidance on effecting this. Or have I in my mind overcomplicated this task?___ 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: convert password from SecKeychainFindGenericPassword to NSString
On Jan 31, 2010, at 9:53 PM, Jens Alfke wrote: No. You don't want to pass a null terminated string to anything but the methods that explicitly take a C string. Anything else just wants the characters, with no nulls. --Jens {via iPhone} NSString's +stringWithCString:encoding: does require a NULL terminated C string [1]. My code worked fine with NSString's +stringWithCString:length: even though the string was not NULL terminated. When I changed that to +stringWithCString:encoding: I would *sometimes* get incorrect results. When I added the code to copy the suppled non-null terminated string to a new buffer with a null termination (prior to calling +stringWithCString:encoding:), the results were made proper again. [1] from the NSString documentation http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/occ/clm/NSString/stringWithCString:encoding: + (id)stringWithCString:(const char *)cString encoding:(NSStringEncoding)enc Parameters cString: A C array of bytes. The array must end with a NULL character; intermediate NULL characters are not allowed. On Jan 31, 2010, at 6:28 PM, Stuart Malin stu...@zhameesha.com wrote: On Jan 31, 2010, at 9:12 PM, Kyle Sluder wrote: On Sun, Jan 31, 2010 at 5:51 PM, Stuart Malin stu...@zhameesha.com wrote: I acquire a password from a keychain using SecKeychainFindGenericPassword. That provides a non null terminated c string and a length. I had been using [NSString stringWithCString: length:] to get an NSString instance of the password. However, the +stringWithCString:length: method was deprecated way back, so I thought I'd clean up my code and use +stringWithCString:encoding: -- however that doesn't work because the supplied C string isn't null terminated. I did a bit of searching, and found in the archives on CocoaBuilder [1] someone's solution back in September of 2005, which was to copy the acquired password to a new buffer of 1 additional byte and create a new null terminated C string there: You could wrap the provided buffer with an NSData and use -[NSString initWithData:encoding:]. If I use +dataWithBytes:length: then I need to specify a length 1 greater, and that additional byte must be set to 0 (to null terminate the string). So, I could use NSMutableData, then -resetBytesInRange: to zero out the last byte, which requires creating an NSRange struct, and that all seems heavier than just using the C code. But then, the processor is fast, and this is code that is run rarely, so optimizing isn't important. I guess it is just a question of style... ___ 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: convert password from SecKeychainFindGenericPassword to NSString
On Jan 31, 2010, at 9:49 PM, Kyle Sluder wrote: On Sun, Jan 31, 2010 at 6:28 PM, Stuart Malin stu...@zhameesha.com wrote: If I use +dataWithBytes:length: then I need to specify a length 1 greater, and that additional byte must be set to 0 (to null terminate the string). So, I could use NSMutableData, then -resetBytesInRange: to zero out the last byte, which requires creating an NSRange struct, and that all seems heavier than just using the C code. But then, the processor is fast, and this is code that is run rarely, so optimizing isn't important. I guess it is just a question of style... This is not true. The data you provide does not need to be a null-terminated C string. Though I'd use Stephen's approach because you don't have to create a wrapper data object. Proof that it works: #import Foundation/Foundation.h int main(int argc, char **argv) { char p[5] = {'H', 'e', 'l', 'l', 'o'}; NSString *s = [[NSString alloc] initWithBytes:p length:5 encoding:NSUTF8StringEncoding]; NSLog(@s = %@, s); [s release]; return 0; } Ah, in my desire to use a class factory method, I overlooked initWithBytes:length:encoding: which does exactly what I need. It is interesting to me that a class convenience method wasn't provided as such would replace the deprecated function. Also wish that the documentation for stringWithCString:length: suggested using this init method with autorelease. Anyway, 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
convert password from SecKeychainFindGenericPassword to NSString
I acquire a password from a keychain using SecKeychainFindGenericPassword. That provides a non null terminated c string and a length. I had been using [NSString stringWithCString: length:] to get an NSString instance of the password. However, the +stringWithCString:length: method was deprecated way back, so I thought I'd clean up my code and use +stringWithCString:encoding: -- however that doesn't work because the supplied C string isn't null terminated. I did a bit of searching, and found in the archives on CocoaBuilder [1] someone's solution back in September of 2005, which was to copy the acquired password to a new buffer of 1 additional byte and create a new null terminated C string there: buffer = (char *) malloc((passwordLength + 1) * sizeof(char)); strncpy(buffer, passwordData, passwordLength); buffer[passwordLength] = 0; password = [NSString stringWithUTF8String:buffer]; free(buffer); Of course I would now change the NSString class method to +stringWithCString:encoding. Is this the best way to go about converting the string returned by the Carbon keychain code to an NSString? I am presuming I should stop using the deprecated method -- is that right? Or can I safely continue to use it? TIA for your wise counsel. [1] http://www.cocoabuilder.com/archive/cocoa/145676-seckeychainfindgenericpassword.html?q=SecKeychainFindGenericPassword#145681 (expand the 22:57 post by Ryan Britton)___ 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: convert password from SecKeychainFindGenericPassword to NSString
On Jan 31, 2010, at 9:12 PM, Kyle Sluder wrote: On Sun, Jan 31, 2010 at 5:51 PM, Stuart Malin stu...@zhameesha.com wrote: I acquire a password from a keychain using SecKeychainFindGenericPassword. That provides a non null terminated c string and a length. I had been using [NSString stringWithCString: length:] to get an NSString instance of the password. However, the +stringWithCString:length: method was deprecated way back, so I thought I'd clean up my code and use +stringWithCString:encoding: -- however that doesn't work because the supplied C string isn't null terminated. I did a bit of searching, and found in the archives on CocoaBuilder [1] someone's solution back in September of 2005, which was to copy the acquired password to a new buffer of 1 additional byte and create a new null terminated C string there: You could wrap the provided buffer with an NSData and use -[NSString initWithData:encoding:]. If I use +dataWithBytes:length: then I need to specify a length 1 greater, and that additional byte must be set to 0 (to null terminate the string). So, I could use NSMutableData, then -resetBytesInRange: to zero out the last byte, which requires creating an NSRange struct, and that all seems heavier than just using the C code. But then, the processor is fast, and this is code that is run rarely, so optimizing isn't important. I guess it is just a question of style... ___ 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
My app died in _CG_spin_lock_try and I don't know what to make of this
I'd appreciate some insight... alas, I don't have much good info... I was running my app from Xcode... my app's window suddenly disappeared, and GDB started up, so I opened the Debugger window. There was no textual indication of why the app had died (that is, _no_ display of something like EXEC_BAD_ACCESS). Here's the stack trace back to my code, which (as you can see) invoked -drawAtPoint on an NSImage. #0 0x92d71b0d in _CG_spin_lock_try #1 0x92d9c106 in CGAccessSessionCreate #2 0x92d984ec in img_data_lock #3 0x92d97329 in CGSImageDataLock #4 0x9657e5e3 in ripc_AcquireImage #5 0x9656c96d in ripc_DrawImage #6 0x92d970fd in CGContextDrawImage #7 0x9053dbff in -[NSCGImageRep drawInRect:] #8 0x9053db63 in -[NSCGImageRep draw] #9 0x90493ff9 in -[NSCachedImageRep draw] #10 0x903e338c in -[NSImage drawInRect:fromRect:operation:fraction:] #11 0x90480e37 in -[NSImage drawAtPoint:fromRect:operation:fraction:] The assembler code for the the _CG_spin_lock_try method was the xchg command in this dissassembly: 0x92d71b04 + mov0x4(%esp),%ecx 0x92d71b08 +0004 mov$0x1010101,%eax 0x92d71b0d +0009 xchg %eax,(%ecx) 0x92d71b0f +0011 xor$0x1010101,%eax 0x92d71b14 +0016 ret 0x92d71b15 +0017 nopl (%eax) If there is anything useful that can be inferred from this that would help me understand what happened (so I can try to recreate and debug), I'd appreciate hearing. TIA. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Compile error using @synchronized on methods that return values
On Nov 8, 2009, at 2:56 PM, Adam R. Maxwel wrote: On Nov 8, 2009, at 3:03 AM, Ken Tozier wrote: Control reaches end of non-void function I Googled for Objective-C accessors and @synchrinized which seemed to indicate that the following was the correct way to handle it - (id) someMethod { @synchronized(self) { return [somevalue autoreleae]; } } But I get the above error whenever I try to do it that way. Here's one of the actual methods with and without the @synchronized directive http://lists.apple.com/archives/Xcode-users/2009/Aug/msg00230.html More info can be found using google: http://www.google.com/search?hl=enq=site%3Alists.apple.com+%40synchronized+Control+reaches+end+of+non-void+functionaq=foq=aqi= Whether this warning is a bug (as suggested by the 00230 post referenced above) or not, I don't know (I'm way at the extreme end of my programmer's union card on this one). But I suspect that from the posters comments in the post I reference below, it isn't a bug. The problem is, you can't return up the calling chain while being synchronized. Do whatever work it is that needs to be performed in a synchronized way, then return whatever result needs to be returned. Here's the post I found (using the Google search supplied by Adam): http://lists.apple.com/archives/Xcode-users/2006/Sep/msg00111.html ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Curious about SSH -- actually about: Keychain -- (passive aggressive)
On Oct 18, 2009, at 11:13 PM, Brent Smith wrote: thanks for the help all. Theres no need to be passive aggressive What you perceived as passive aggressive is... I.S.'s style, which, if you were a regular reader of the list, you'd be familiar with; a style that (I suspect) ameliorates his frustration and enables him to answer yet-once-again a query that should never have been posted, and do so with useful guidance, all in the hopes (I further suspect) that if others would read, the list would become a place of ever-more streamlined activity. There are many very smart and experienced programmers on this list who take much of their valuable time to answer posts. With so much good information flowing, a non-expert programmer can learn much by reading responses to other people's posts -- this is certainly the case for me. Alas, it seems that many people don't read the list actively, and then, when they have a question, they post as if their circumstance are unique. Yet, most often such is not the case, the issue been dealt with before, or an answer is readily available. There have been endless replies made to posters of suggesting that they first do a search, that the pose their problem informatively, and that they explain what they have tried (when it is a coding problem)... yet over and over people come to the list and ask malformed or trivial questions as if they have never seen any of this contextualizing guidance. The smart folks on the list can't keep answering such questions over and over - it is much too tedious (or so I suspect, as I am not one of them). Continuing to answer such questions directly encourages laziness, vitiates the quality of the list, and would drive expertise away, and so to counteract such, I.S. jumps in and short circuits such queries, counseling the poster to do a little bit of self-help work first. Should one make a reasonable effort to answer a question or solve a problem, but still come up short, then one is welcome to post to the list, and preferably should do so cognizant of the guidance that has over-and-over been posted here about how to frame a query, so that the experienced can quickly determine if they are knowledgeable in the problem domain, zero in on the actual problem, and provide an actionable response, all in an expedient and time-effective manner. These folks can be quite compassionate: I have on more than one occasion asked a bumble-headed question -- after all, stupidity and blindness happen; but I do try and frame my questions well and explain what I've tried; when I do so, I receive patient and informative responses sans sarcasm. The smart people here are here of their own volition and desire to help -- let's not abuse them. ___ 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: NSURLConnection timeout -- what happens?
On Oct 15, 2009, at 3:59 PM, Jens Alfke wrote: On Oct 15, 2009, at 11:44 AM, Stuart Malin wrote: I have looked through the NSURLConnection class reference, the NSURLRequest class reference, the URL Loading System guide, queried Google, searched mailing list archives, and even looked through NSURLConnection.h, but can not find documentation about what happens when an NSURLConnection times out. I presume that -- for the asynchronous case -- the invoker's - connection:didFailWithError: selector will be messaged. Is this so? Where is that defined? I think so, but I don't remember for sure. Why not try it? Set a timeout of 0.1 sec and send a request to a slow server. (shhepishly): good suggestion. Have done so: yes, an error is the result with code 1001, which is defined in NSURLError.h as NSURLErrorTimedOut But I haven't been able to find any documentation of what the possible errors are, and what the data would be for those reported failures. NSURLError.h. Sure enough -- there they are. But in practice you can sometimes get errors from other domains too, especially if SSL is involved. Well, logging will again be my friend :-) The URL Loading System guide has an example that uses the key NSErrorFailingURLStringKey to access a value from the error object's userInfo dictionary. Where might other such keys be defined? Tip: To see where a symbol is defined, hold down Command and double- click it. If you'd done that with that key, it would have taken you to NSURLError.h and answered part of your question. Ah, I hadn't tried copying that symbol from the docs to Xcode in order to search for its definition -- that's a good idea that I will hold for the future. Also, thanks for the Command-double-click tip -- I had been doing Option-click and then selecting Jump to definition from the contextual menu. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
NSURLConnection timeout -- what happens?
I have looked through the NSURLConnection class reference, the NSURLRequest class reference, the URL Loading System guide, queried Google, searched mailing list archives, and even looked through NSURLConnection.h, but can not find documentation about what happens when an NSURLConnection times out. I presume that -- for the asynchronous case -- the invoker's -connection:didFailWithError: selector will be messaged. Is this so? Where is that defined? Also, the class reference for NSURLConnection's - connection:didFailWithError: says of the provided NSError object: An error object containing details of why the connection failed to load the request successfully. But I haven't been able to find any documentation of what the possible errors are, and what the data would be for those reported failures. The URL Loading System guide has an example that uses the key NSErrorFailingURLStringKey to access a value from the error object's userInfo dictionary. Where might other such keys be defined? Can someone please point me to appropriate reference materials. TIA, --Stuart ___ 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
Help with NSURLConnection memory fault
I create (in an object) an NSURLConnection and start it asynchronously: mNSURLConnection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self]; [mNSURLConnection start]; I release the NSURLConnection instance after it calls back in -connectionDidFinishLoading: -connection:didFailWithError: My code proceeds on its merry way, eventually releasing a bunch of objects, one of which was object that created the NSURLConnection instance (and had set itself as the delegate for that connection). Alas, when that object is deallocated, the app crashes (since I am running in Xcode, gdb is attached), and the stack trace shows: #0 0xa078900c in objc_assign_ivar #1 0x92a64558 in -[NSURLConnection(NSURLConnectionReallyInternal) releaseDelegate] #2 0x92a644e4 in _NSURLConnectionReleaseClient #3 0x902cbc4d in ClientContextHolderCFURLConnectionClient_V4::forget #4 0x902ca3f6 in URLConnectionClient::processEvents ... I don't know what to make of this, other than I know that the delegate object is already deallocated. But, the NSURLConnection object was also, and earlier, so I don't understand why it appears to still exist, especially so late, and is still referring to its delegate. I'd appreciate any advice about what I should go looking after to track this down, as I am reasonably certain that the sequence of my object deallocations is proper (based upon NSLog() calls in the - dealloc methods). ___ 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
[SOLVED] Re: Help with NSURLConnection memory fault
On Oct 14, 2009, at 7:24 PM, Jens Alfke wrote: It looks as though your object (the delegate) got dealloced too early, before the NSURLConnection finished loading. This shouldn't be possible, since the connection object retains the delegate, but you may have too many release calls to it someplace. What I would do next is set a breakpoint in your class's dealloc method, and also in its -connectionDidFinishLoading: and - connection:didFailWithError:, and see which gets called first. Thanks for the reply, Jens. As I suspected, the time sequence ordering of the releases was just fine. The problem was releasing the NSURLConnection object twice, once when the connection had concluded, and again when the object that had created it was dealloc'ing (because I hadn't nil'd the pointer to the connection object after releasing it). Just a lucky coincidence that the memory where the dealloc'd NSURLConnection had lived was still the (now defunct) object, so it went through its motions again, and tried to release the delegate a second time. ___ 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: no display until header clicked
On Oct 5, 2009, at 1:13 PM, David Hirsch dhir...@mac.com wrote: Thanks, Volker. rearrangeObjects did work, but I don't understand why that call should be necessary. If anybody out there wants to educate me, I'd appreciate it. (More info: I have my ArrayController in IB bound to an array (phases) of File's Owner (which is my NSDocument subclass). In the document's init method, I make phases an empty NSMutableArray, and in the document's windowControllerDidLoadNib method, I populate that array with data.) Dave, An NSMutableArray is not KVO compliant for addition and deletion of entries. You must either provide manual notification or create a class with a To-Many property that is KVO compliant. From the Key Value Observing Programming Guide -- Automatic notification is also supported for the collection proxy objects returned by mutableArrayValueForKey: and mutableSetValueForKey: . This works for to-many relationships that support the indexed accessor methods insertObject:inKeyAtIndex:,replaceObjectInKeyAtIndex:, and removeObjectFromKeyAtIndex:. http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/KeyValueObserving/Concepts/AutoVsManual.html#/ /apple_ref/doc/uid/20001844 To implement a KVO compliant class for a To-Many property, read more about Collection Accessor Patterns for To-Many Properties in the Key Value Coding Programming Guide http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/KeyValueCoding/Concepts/AccessorConventions.html Which says: For manipulating the contents of the collection it is best practice to implement the additional accessor methods referred to as the collection accessor methods. To do so, you must provide a minimal complement of indexed accessors (you may certainly use an NSMutableArray as a backing store). HTH, --Stuart -Dave On Oct 5, 2009, at 9:40 AM, Volker in Lists wrote: Hi, without knowing how you add objects to the ArrayController - and when, and without knowing what and how is bound exactly - guessing is most that can be done. It seems the bindings are okay from the beginning, but the changes to the ArrayControllers content are only observed when the sortOrder is changed. Maybe you need only a single [NSArrayController rearrangeObjects] call or similar. Volker Am 05.10.2009 um 18:32 schrieb David Hirsch: My window has two NSTableViews. Each has two columns, each of which is bound to a field in Phases, an NSArrayController. When my window is displayed, I calculate my model, and the NSTableViews show the headers, but blank data cells. However, when I click the header of one table, all four columns get populated with data. As far as I can tell (I've set breakpoints), this happens without calling any of my code. Note that this only works if I click a text-based column. If I click the column with image cells, I get no response, so presumably the TableView is trying to sort the data on the click, and somehow straightens out the previously mucked-up binding at that time. I'm posting here without code to see if anybody has experienced this before. It will be a major undertaking to reduce this problem to a post-able amount of code. I've tried making Phases (the NSArrayController) the data source and delegate in addition to the column bindings, without solving the problem. I've tried adding another NSTableView and binding it to other columns to see if I had done it wrong the first time. That did not help. The fact that the bindings do work after the click seems to suggest that the binding setup is okay. Thanks in advance, Dave ___ 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 do i make SecKeyRef object from NSData of publicKey value
On Sep 28, 2009, at 1:05 AM, bosco fdo wrote: Date: Mon, 28 Sep 2009 11:57:29 +0800 From: bosco fdo bos1t...@gmail.com Subject: how do i make SecKeyRef object from NSData of publicKey value To: cocoa-dev@lists.apple.com Message-ID: 630900f20909272057o5d14eaf7ue104e9f71c8b1...@mail.gmail.com Content-Type: text/plain; charset=ISO-8859-1 Hi I need to do RSA encryption for that i need to have SecKeyRef object for the public Key i have. Do i still need to add to the Keychain and get from the Keychain as a SecKeyRef ? Is there any way i can convert my publicKey value from NSData bytes to SecKeyref ? Please help with sample code Perhaps the Cocoa code here may be helpful to you: http://www.iphonedevsdk.com/forum/iphone-sdk-development/17242-rsa-generating-keypair-so-slowly.html ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
[JOB] iPhone development gig in Tampa, FL.
Hi John, I've got some decent Objective-C/Cocoa experience. Have only dabbled with Cocoa Touch, but can come up to speed. I'd only be interested in contract work, as I have a big project of my own, but some paying work to keep that going would be good for me. I am living down in southeast Florida (Palm Beach county), so can get up to Tampa on a regular basis. I can tell you a bit more... but first want to know if contract would be okay, because it seems from your post that permanent is preferable. Also want to hear from you about the scale of the project -- is it expected to be months or years :-) --Stuart On Sep 23, 2009, at 10:02 PM, cocoa-dev-requ...@lists.apple.com wrote: Date: Wed, 23 Sep 2009 15:13:26 -0700 From: John C. Randolph j...@mac.com Subject: [JOB] iPhone development gig in Tampa, FL. To: Cocoa Dev List Cocoa-dev@lists.apple.com Message-ID: 4b0556ee-f1bf-4d36-9a03-6236de5ff...@mac.com Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Ladies and Gentlemen, Looks like I'm about to go to Florida for a month, and the client wants me to help them find someone to join them on a permanent basis. The work is an in-house app for managing their service vendors and streamlining their billing processes. If you've got a solid Objective-C Cocoa or Cocoa Touch background and you're interested, drop me a note at jcr at mac.com. I have advised the client of what the market rates are, so they won't be asking you to take java-monkey rates for iPhone work. Contract or permanent is negotiable. -jcr ___ 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
What is the life of the c string returned by NSString's UTF8String method?
I am under the impression that the reference returned by NSString's UTF8String method is valid for the life of the NSString instance which provided the reference (and further, that the memory of the referenced C string is freed when the NSString is released). Is this correct? I have a class with some (statically allocated) class variables. In the class's -initialize method, I create a retained NSString. I set one of the class variables to the value returned by -UTF8String (as sent to that retained NSString). I use this char* value in some C calls made from instance methods of the class. The first time an object of the class is instantiated, this works fine. But it seems that for subsequent instances, although the value of the char* pointer remains unchanged, the memory it is pointing to is changed (i.e., no longer a C string representation of the NSString). So, either the NSString has done something with the memory pointed to by the initialized reference (i.e., I can't hold onto the reference as I have been), or somehow the memory is getting corrupt in some other way. I will look into the latter but only if my assumption about the former is correct. TIA. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: What is the life of the c string returned by NSString's UTF8String method?
On Sep 18, 2009, at 2:20 PM, Sean McBride wrote: On 9/18/09 2:04 PM, Stuart Malin said: I have a class with some (statically allocated) class variables. In the class's -initialize method, I create a retained NSString. I set one of the class variables to the value returned by -UTF8String (as sent to that retained NSString). I use this char* value in some C calls made from instance methods of the class. It would be much safer to just call -UTF8String as needed. Or have you found that it is a bottleneck in your code? Not a bottleneck, merely another case of misguided attempt to optimize. Gotta learn not to do that unless the need is proven. ___ 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
SCNetworkReachability and impact of Snow Leopard
I am writing some code on 10.5 Leopard that uses SCNetworkReachability. The latest documentation (SysConfig.pdf dated 2009-07-30) shows the Network Reachability Flags (with names such as kSCNetworkReachabilityFlagsReachable) as being declared in SCNetworkReachability.h as of 10.6. However, on 10.5, the flags (appear to me) to be defined in SCNetwork.h, and have names like kSCNetworkFlagsReachable. Question: What is the best way for me to write code now that will be compliant with 10.6 Snow Leopard? Should I conditionally compile and test against different flags? Or just keep using the SCNetwork.h enum values until and unless I need one of the newly-defined-in-10.6 values? ___ 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
setFrameSize called multiple times for a single size change?
I have a sub-classed TableView that is the document view of an ScrollView. The rows of the TableView are composited by a custom cell, and soI have overridden the -setFrameSize method of the TableView in order to determine if any rows have changed height as a consequence of the resize (if so, I invoke - noteHeightOfRowsWithIndexesChanged). After performing that calculation (and call to inform the table if any rows did change height), I then call the -setFrameSize of the super class (the NSTableView). What I am seeing is that upon invoking the super class's -setFramSzie method, the overridden -setFrameSize is invoked twice more: the first time with the *old* size, then twice with the new size. While my app functions, I am troubled by these seemingly extra calls, and wonder if I haven't configured some setting of the TableView or ScrollView that I should. All of these objects are instantiated programmatically (not in IB). I set a breakpoint to examine the calling stack to see what was going on. The call to set the old size comes from -resizeWithOldSuperviewSize. The docs say this can be overriden, so I have done so, making it a no- op method (that is, not invoking the super class). My app seems to perform just fine. Question 1 -- Is this okay to do?? The two calls for the new size come, it seems to me, as a consequence of the TableView sizing the column (there is only one column in the table), as indicated by these two calling stacks: #0 0x00041148 in -[TweetsListTableView setFrameSize:] at TweetsListTableView.m:181 #1 0x93ba6057 in -[NSTableView tile] #2 0x93baefcf in -[NSTableColumn setWidth:] #3 0x93baeae0 in -[NSTableView _sizeTableColumnsToFitWithStyle:forceExactFitIfPossible:] #4 0x93bae24a in -[NSTableView _sizeTableColumnsToFitForAutoresizingWithStyle:] #5 0x93bae1d4 in -[NSTableView sizeLastColumnToFit] #6 0x93bae00f in -[NSTableView _autoresizeToFit] #7 0x93badd34 in -[NSTableView superviewFrameChanged:] #0 0x00041148 in -[TweetsListTableView setFrameSize:] at TweetsListTableView.m:181 #1 0x93ba6057 in -[NSTableView tile] #2 0x93bae1e6 in -[NSTableView sizeLastColumnToFit] #3 0x93bae00f in -[NSTableView _autoresizeToFit] #4 0x93badd34 in -[NSTableView superviewFrameChanged:] I now cache the last size given to the -setFrameSize method, and don't perform my testing for row height changes if the width hasn't changed, so I am no longer incurring that calculation cost. Question 2 -- Is there a better way to configure the single column's resizing mask to avoid the double call? TIA, --Stuart ___ 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: setFrameSize called multiple times for a single size change?
On Jul 21, 2009, at 9:17 AM, Stuart Malin wrote: I now cache the last size given to the -setFrameSize method, and don't perform my testing for row height changes if the width hasn't changed, so I am no longer incurring that calculation cost. Question 2 -- Is there a better way to configure the single column's resizing mask to avoid the double call? My bad -- I figured out an answer to the second question after posting... Since I have only one column, I now set the columnAutoresizingStyle of the TableView to NSTableViewFirstColumnOnlyAutoresizingStyle In the past, I had multiple columns, and had instead set this to - NSTableViewSequentialColumnAutoresizingStyle I guess that the TabbleView doesn't notice that there is only one column, and so it was generating two resizing calls. ___ 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: setFrameSize called multiple times for a single size change?
On Jul 21, 2009, at 9:27 AM, Kyle Sluder wrote: On Tue, Jul 21, 2009 at 9:17 AM, Stuart Malinstu...@zhameesha.com wrote: I have a sub-classed TableView that is the document view of an ScrollView. For future reference: TableView and ScrollView are not names of classes in Cocoa. NSTableView and NSScrollView are; UITableView and UIScrollView exist in Cocoa Touch, so it's important to make this distinction. Good point. I was referring to NS, not UI, and will be clearer in the future. The rows of the TableView are composited by a custom cell, and soI have overridden the -setFrameSize method of the TableView in order to determine if any rows have changed height as a consequence of the resize (if so, I invoke -noteHeightOfRowsWithIndexesChanged). After performing that calculation (and call to inform the table if any rows did change height), I then call the -setFrameSize of the super class (the NSTableView). You're doing this backwards. Your delegate should be telling your table view the size of the rows. Have your delegate listen for NSViewFrameDidChangeNotification from the table view, and have it call -noteHeightOfRowsWithIndexesChanged:. Ah yes, this makes sense -- I will recode. Thank you Kyle! ___ 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: NSTextView without NSScrollView
On Jul 17, 2009, at 5:38 PM, James Walker wrote: Is there a way to have an NSTextView that is not enclosed in an NSScrollView? IB doesn't seem to want to let me. It would be for displaying static rich text (certain things are harder, or maybe even impossible, to do with NSTextField). I know I can turn off drawing of the NSScrollView border, but it throws off the layout, because there's a margin around the text, at least on the left. I do this in an app I am working on. I do *not* create the NSTextView in IB, but rather do so programmatically. You'll need to call its - initWithFrame method to initialize, and then add as a subview to its containing view. I also interact directly with the underlying text system (Text Container, Layout Manager, and Text Storage) in order to set the text, determine the size of the laid out text, and position for presentation and interaction. Getting all that to work took me a fair amount of exploration and reading of the relevant class documentation and other text-related information provided by Apple. ___ 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
NSLinkAttributeName: can I control the visual presentation?
I have a mutable attributed string that is displayed in an NSTextView. For a certain range, I set several attributes, including NSLinkAttributeName. However, the presentation shows as blue underlined text even though I have set other attributes for the font color and also have set the underline style to none. Is there something else I must do to control the visual presentation? Or am I going to need to use tracking areas and manage this with dynamic changes? ___ 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: Font Panel and storing font user default
On Jun 15, 2009, at 6:31 PM, Stuart Malin wrote: I am replying to my own posting with updated info, for the archives... I would like for my app to enable the user to set a user default for a Font to be used in a certain part of the application. I have a preferences panel, and within that am able to open the NSFontPanel. However, I can't figure out how to capture the setting that is made: must I actually have some text (say in a Text View) that is edited? I had been invoking the NSFontManager from outside the App delegate, which was the final place I managed to intercept the changeFont: call (as it rode up the Responder chain). Alas, I had tried setting the delegate for the Font Manager to call the object that needed the result of the Font Panel settings made by the user. I then had my aha when I found the -setAction and -setTarget methods; setting these solved that problem. Also, I had been separately invoking the NSFontManager and the NSFontPanel. Rather than open an instance of the Font Panel directly, I have the Font Manger do it: [fontManager orderFrontFontPanel:nil]; With these changes, my app can open the Font Panel from some controller other than the App delegate, and capture the settings made by the user. For completeness, the invoking method code is (of course this has details specific to my app): NSFontManager *fontManager = [NSFontManager sharedFontManager]; [fontManager setTarget: self]; [fontManager setAction:@selector(changeFontForInfoText:)]; [fontManager setSelectedFont:mInfoTextFont isMultiple: NO]; [fontManager orderFrontFontPanel:nil]; The method that is informed of the font changes made in the Font Panel is simple: - (void) changeFontForInfoText:(id)sender { NSFontManager *fontManager = [NSFontManager sharedFontManager]; NSFont *font = [fontManager convertFont:[fontManager selectedFont]]; // do whatever else needs to be done with the new font } Also, is it possible to save an NSFont as an object in user preferences? Or must I save off the parts of the font specification separately: font name, size, attributes. I tried various approaches, including storing and loading the attributes dictionary of the NSFontDescriptor for the font. In the end, I just save two fields, the font name and the point size. While this doesn't allow for saving and restoring detailed tweaks to the font, my app doesn't need such, and the two field approach requires less manipulation of intermediary objects, so I opted for that approach. ~~~ hope this info is useful to someone someday ___ 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 detect a click on app's dock icon (when the app is active)?
I have a non Document based app. If the window is closed, I want to have the user be able to get it back by clicking on the dock icon. (Note that Apple's Mail does this). I have implemented NSApplication's - (void) applicationDidBecomeActive:(NSNotification *)notif but that is only invoked if the dock icon is clicked when the app is not active. I need to know when it is clicked while the app is active. I've looked through various docs, searched with Google, and on Cocoabuilder, but the answer has eluded 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: How to detect a click on app's dock icon (when the app is active)?
On Jun 7, 2009, at 3:05 PM, Andy Lee wrote: On Jun 7, 2009, at 8:50 PM, Stuart Malin wrote: I have a non Document based app. If the window is closed, I want to have the user be able to get it back by clicking on the dock icon. (Note that Apple's Mail does this). I have implemented NSApplication's - (void) applicationDidBecomeActive:(NSNotification *)notif Instead of that, implement these: - (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender; - (BOOL)applicationOpenUntitledFile:(NSApplication *)theApplication; Have the first one return YES and have the second one reopen your window. They work even in a non-document-based app. Thanks, Andy; works! Q: I presume it doesn't matter what value is returned for - applicationOpenUntitledFile (I happen to be returning NO because no file was opened). but that is only invoked if the dock icon is clicked when the app is not active. I need to know when it is clicked while the app is active. I've looked through various docs, searched with Google, and on Cocoabuilder, but the answer has eluded 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: Bindings and KVO of View objects
On May 20, 2009, at 1:04 AM, Quincey Morris wrote: On May 19, 2009, at 17:22, Stuart Malin wrote: I don't see why it is a design flaw to want to bind to the selectedIndex of a segmented control so that when the user changes the selected segment, my code to take action. Binding to the control is conceptually quite similar. The two approaches to me seem to be matters of implementation specifics. I'm not quite sure what you're saying here. You can't bind *to* the selectedIndex of a segmented control because (again) there's no such property -- selectedIndex is a binding name, not a property name. You can bind to the selectedSegment of a segmented control, and that will indeed produce a notification when the state of the control changes. But that's just about terminology. NSSegmentedControl exposes a selectedIndex binding; there's no such property. Further, there's no binding for selectedSegment, which is a property. Curiously asymmetric. My point was this: Binding to the state of a control only tells you the state of the control. If you reason, Oh, but the control is bound to a data model value, so the state of the control always reflects the data model value then you've introduced a lot of information about the interface implementation with no actual benefit -- if your information is correct, then you may as well have bound directly to the data model. Really (or so runs my argument) the only case where there's any point in binding to a user interface element is when you definitely want to know the UI element's state, and not the data model value, in a situation where the two could be different. (Again, if they can't be different, then binding to the data model value is the better choice.) Good points, well-taken. Also, on May 19, 2009, at 14:18, Stuart Malin wrote: My specific concern is with NSSegmentedControl, which has a bindable property selectedIndex. I am trying to add an observer for this property (using -addObserver: on an instance). So you've written code which unnecessarily knows about the construction of the user interface, so the UI is no longer neatly partitioned off in your NIB file. Changing the UI means you'll have to change code. But if you observe the data model instead, the UI is not a factor or a maintenance headache. Also a good point, a key one in fact, for this is a driving reason for MVC. In the specific case which I am working with, the UI element does not correspond to a model value of the application's data. The control is used only to change the presentation of the model data. Hence, a change to the UI would necessitate, well, corresponding changes to the UI. In my implementation, only the UI controller (for this portion of the UI) is affected by the state change of the segmented control. I guess one could make an argument for the case that this presentation state is a model attribute of the UI. My solution turned out to be best handled by setting the selector and target for the action of the control. On invocation of the specified method, the controller adjusts the UI accordingly. Works very cleanly, as the NSSegmentedControl takes care of changing its visual state. Presently, there is no other way for this state to change, but if I introduce one (say a menu option), then my controller could always directly update the state of the segmented control. Which would suggest having a UI model property of that state and binding the control to it Anyway, all that said, thank you Quincy for your considered thoughts. ___ 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
Bindings and KVO of View objects
As my understanding of Bindings is that they implement using KVO and KVC, then is it safe to assume that if an object has a bindable property, then that property should be observable with KVO, yes? My specific concern is with NSSegmentedControl, which has a bindable property selectedIndex. I am trying to add an observer for this property (using -addObserver: on an instance). Alas, I am not getting an observer event (i.e, invocation of my -observerForKeyPath:... method) when I change the segmented control in the U/I. So, either I have done something incorrectly in setting up the observer, or this is not an observable property. In searching the archives, I came across a statement by mmalc that View's don't emit KVO notifications (http://www.cocoabuilder.com/archive/message/cocoa/2007/6/29/185375 ). If this is so, then how can the NSSegmentedControl (which is an NSView) support bindings? ___ 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: Bindings and KVO of View objects
On May 19, 2009, at 1:44 PM, Kyle Sluder wrote: On Tue, May 19, 2009 at 7:01 PM, Quincey Morris quinceymor...@earthlink.net wrote: On May 19, 2009, at 14:18, Stuart Malin wrote: No. The name of the binding is *not* the same as the name of any property of the bound object. For example, most controls have a value binding, but controls don't have a value property. Actually, be careful if you're implementing a bindable object. I believe the default implementation of -bind:toObject:withKeyPath:options: actually uses the provided key as a property, even though this isn't documented anywhere. I realized after I issued my post that I had inverted the thinking regarding KVO . For bindings, the KVO is used to observe the property that is *given* to the binding in the - bind:toObject:withKeyPath:options: method call. The assumption underlying your assumption, that there is some sort of direct correlation between a binding and an underlying property, is also false. Typically, bindings will be implemented so as to use one or more properties of the bound object, but that's not a requirement (except perhaps in a looser conceptual sense). This point needs to be made more clearly: binding names and properties live in separate namespaces. Yes: there is no correlation between a named binding and any underlying property. ___ 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: Bindings and KVO of View objects
On May 19, 2009, at 1:44 PM, Quincey Morris wrote: On May 19, 2009, at 14:18, Stuart Malin wrote: snip My specific concern is with NSSegmentedControl, which has a bindable property selectedIndex. I am trying to add an observer for this property (using -addObserver: on an instance). Alas, I am not getting an observer event (i.e, invocation of my - observerForKeyPath:... method) when I change the segmented control in the U/I. So, either I have done something incorrectly in setting up the observer, or this is not an observable property. snip Finally, it usually indicates a design flaw if you're trying to observe a property of a user interface object. It's almost always better to observe the value that the UI object is bound to. (There are valid exceptions, though.) I don't see why it is a design flaw to want to bind to the selectedIndex of a segmented control so that when the user changes the selected segment, my code to take action. Binding to the control is conceptually quite similar. The two approaches to me seem to be matters of implementation specifics. ___ 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
Getting Unknown class 'someClassName' in nib file message
I have tried both Google and searching the archives regarding the problem with the subject message, but can only find cases where someone has a class and didn't include it. My case is different: in my project, I renamed a class. I have made appropriate changes in both Xcode and IB for this (dragging the new .h file to the Nib's document window in IB and redeclaring the class name of the affected object in the inspector). Yet I receive the subject message in the run log. Actually, receive it multiple times. I have used the Find In Project function of Xcode to ensure I have no lingering references to the old class name. I have even examined the Nib's .xib file and searched for the old class name, and don't find it. Somewhere a reference to the old name is lingering... how might I find it? ___ 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: Getting Unknown class 'someClassName' in nib file message
Thanks Jon for the quick reply. I had already found the culprits -- my fault: I had two other Nibs that contained objects that were declared to be of the old class. I found by manually looking in each .xib file. Thanks for the info about the object outline view in IB -- that might have been easier than opening the xib files in an editor. I had tried using the Finder's find files mechanism to locate files in the project that contained content of the old class name, but for some reason that didn't work for me. Problem now solved. Onward ho. Thanks again. On May 13, 2009, at 10:30 AM, Jonathan Hess wrote: Hey Stuart - Try putting a breakpoint on NSLog, and then run your app. When you hit the breakpoint, look at the backtrace. It will give you an idea of which NIB is being loaded. After you figure that out, open the NIB/XIB file in IB and in the object outline view make sure the class name table column is showing by right clicking on the table column headers. After this, filter using the search field for the missing class name. If there isn't one, then you should file a bug and attach the Interface Builder document that is issuing the log message. Jon Hess On May 13, 2009, at 1:15 PM, Stuart Malin wrote: I have tried both Google and searching the archives regarding the problem with the subject message, but can only find cases where someone has a class and didn't include it. My case is different: in my project, I renamed a class. I have made appropriate changes in both Xcode and IB for this (dragging the new .h file to the Nib's document window in IB and redeclaring the class name of the affected object in the inspector). Yet I receive the subject message in the run log. Actually, receive it multiple times. I have used the Find In Project function of Xcode to ensure I have no lingering references to the old class name. I have even examined the Nib's .xib file and searched for the old class name, and don't find it. Somewhere a reference to the old name is lingering... how might I find it?___ 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/jhess%40apple.com This email sent to jh...@apple.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
Key-Value Observing: light-weight or heavy-weight?
I've got a situation where I have several hundred objects of a class that have a KVC-compliant property. There are a matching set of other objects that refer to the former. For a problem I need to solve, one solution is for the other objects to observe the property of their counterpart object. That is: object's of class B would observe some property of objects of class A. While I know that this is just the sort of thing that KVO supports, I am wondering if establish hundreds of these observer relationships is a heavy-weight solution, or is each individual observer reasonably light-weight, and this a viable way to go. TIA. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: catching whitespace with scanner
On May 6, 2009, at 7:08 PM, Daniel Child wrote: I'm trying to catch whitespace between words with a scanner. For some reason, the white space is not being recognized. Am I missing something obvious or is there a bug here? Thanks. NSScanner defaults to skipping whitespace and newlines. Try adding the following after you declare your scanner but before you scan: [scanner setCharactersToBeSkipped:nil]; // don't skip whitespace!! See the documentation for this method in the NSScanner Class Reference. ___ 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: problems with live resize of NSTextView
On Apr 25, 2009, at 5:08 AM, Keary Suska wrote: On Apr 24, 2009, at 3:06 PM, Stuart Malin wrote: I have an NSTextView in a custom view, it is set to resize with the containing view only in the horizontal dimension. When I resize the window, the text view does resize, and it does re-layout its content to fit, both on expanding and shrinking. However, the text view not only changes its frame size height, but repositions itself (changing the y value of its frame's origin). Why does it do this? You need to read the Cocoa Drawing Guide and View Programming Guide for Cocoa. The answer is explicit: the 0,0 coordinate of the Cocoa drawing system is the bottom left. Ah, I wasn't clear, because of course the origin would move down as the text expands downward. What I am seeing though is that the origin moves down more than the increase in height, so the text view isn't just expanding, but expanding and moving downward (that is, even its top moves down). More important to me: where is the best place for me to detect this change because I want to change the parent view's height to accommodate any increase in height in the text view. One possible approach is to observe NSViewFrameDidChangeNotification coming from the view. See the NSView documentation for how to use it. Thanks for reminding me of this. I need to see whether the notification occurs before a redraw cycle. If so, I can propagate relevant resizes up the chain of parent views. ___ 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: problems with live resize of NSTextView
On Apr 25, 2009, at 9:17 AM, Keary Suska wrote: On Apr 25, 2009, at 12:05 PM, Stuart Malin wrote: On Apr 25, 2009, at 5:08 AM, Keary Suska wrote: On Apr 24, 2009, at 3:06 PM, Stuart Malin wrote: I have an NSTextView in a custom view, it is set to resize with the containing view only in the horizontal dimension. When I resize the window, the text view does resize, and it does re- layout its content to fit, both on expanding and shrinking. However, the text view not only changes its frame size height, but repositions itself (changing the y value of its frame's origin). Why does it do this? You need to read the Cocoa Drawing Guide and View Programming Guide for Cocoa. The answer is explicit: the 0,0 coordinate of the Cocoa drawing system is the bottom left. Ah, I wasn't clear, because of course the origin would move down as the text expands downward. What I am seeing though is that the origin moves down more than the increase in height, so the text view isn't just expanding, but expanding and moving downward (that is, even its top moves down). Is the NSTextView anchored to both the top and bottom edges? If not, you may get this behavior. It had been fixed only to the top. I tried changing to fix to both, and the behavior remains the same. But this isn't an issue, because in my situation, the parent view needs to be resized to accommodate the text view's present size (see comments below). More important to me: where is the best place for me to detect this change because I want to change the parent view's height to accommodate any increase in height in the text view. One possible approach is to observe NSViewFrameDidChangeNotification coming from the view. See the NSView documentation for how to use it. Thanks for reminding me of this. I need to see whether the notification occurs before a redraw cycle. If so, I can propagate relevant resizes up the chain of parent views. It would probably be better to put the textview in a scrollview (or make the textview's parent an NSScrollView subclass). You wouldn't, for instance, want the window to grow larger than the screen size. The text view's parent is a custom view. There are an ensemble of these custom views in a parent document view (of a scroll view). What I am now doing (not yet complete, but I think this path will work): I've subclassed the text view and have it detect live resizing changes to its height. When that happens, it posts a notification. The enclosing view is an observer for those notifications. When the text view does change size, the parent enclosing view resizes, repositions the text view appropriately, and posts its own didResize notification so the process can proceed up the hierarchy. I've already got the text view detecting its live resize height change and posting the notification. So far, it seems that this is happening before the draw recycle, which is great, but I need to get a bit further to see if this is in fact the case. Thanks for your interest in this, Keary. I appreciate the comments you've made. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
problems with live resize of NSTextView
I have an NSTextView in a custom view, it is set to resize with the containing view only in the horizontal dimension. When I resize the window, the text view does resize, and it does re-layout its content to fit, both on expanding and shrinking. However, the text view not only changes its frame size height, but repositions itself (changing the y value of its frame's origin). Why does it do this? More important to me: where is the best place for me to detect this change because I want to change the parent view's height to accommodate any increase in height in the text view. TIA. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Best practice regarding display of many similar items in a lengthy view
I am building an app that displays a list of composite items. By composite I mean that each item has multiple clickable icons, images, and multiple bits of text. In my first implementation, I modeled these items with a Nib containing a custom NSView and a variety of IB installed sub views (NSImageView, NSTextView, NSButton). Because the user can apply filters to the list, and so the visible subviews would need to be managed, I made inquiry a couple of weeks ago (http://www.cocoabuilder.com/archive/message/cocoa/2009/4/2/233579 ) regarding the best way to handle this (add/remove subviews versus show/hide). I was advised that my approach was a conceptual error and that I should be using cells. I didn't have any experience with cells, and so was hesitant, but since have been rebuilding new functionality using a common custom cell that is used in by NSTableView to render a column (only one column). I have been studying Apple's PhotoSearch example to learn how this is done, and how to handle NSrackingArea entities, because my items can each have many tracking areas. I'm seeking confirmation that using a custom cell to stamp out items is in fact the better approach than having hundreds of views each with a variety of subviews. 1) Because Tracking Areas must be associated with a view, all of the tracking areas (which can be hundreds) are being attached to the table view. Will this be a problem? In my original approach, there were only a handful of tracking areas associated with each view. 2) NSTableView seems (to me) to be causing a lot of repeated calculations to be done. For instance, because my items can vary in height, my table view delegate implements -tableView:heightOfRow: In this method I have to layout all the text against the current column width to determine the item's height. This method is called frequently. Sure, I guess I should be caching the result for a given column width... Anyway, it just seems to me that the table view approach is causing lots of calculations that my view-based approach didn't (they were sized once, and again only when changed). 3) Is there another approach besides an NSTableView that I could be using to stamp out my custom cell on an underlying NSView that is the documentView of a scrollView? Sure, I know I can calculate positions, and call the cell to draw, but I suspect I'd run into myriad details that the table view is already handling, so why re- invent? TIA. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
NSTableView variable row height and noteHeightOfRowsWithIndexesChanged during live resize
I have an NSTableView with a single column that has a custom cell. During a live resize, I recalculate the row height in the delegate method -tableView:heightForRow: and return the result. However, some rows don't grow larger. I presume I need to call the tableview's - noteHeightOfRowsWithIndexesChanged for each row that has a height change. Is it okay to call this from within the tableView:heightForRow: method? I get some glitchy results when I do so: the affected rows are only redisplayed only when they get wider (and hence the height decreases), not when they get narrower (and hence the height increases). ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: NSTableView variable row height and noteHeightOfRowsWithIndexesChanged during live resize
On Apr 23, 2009, at 1:18 PM, Corbin Dunn wrote: On Apr 23, 2009, at 3:37 PM, Stuart Malin wrote: On Apr 23, 2009, at 12:33 PM, Corbin Dunn wrote: On Apr 23, 2009, at 2:55 PM, Stuart Malin wrote: I have an NSTableView with a single column that has a custom cell. During a live resize, I recalculate the row height in the delegate method -tableView:heightForRow: and return the result. However, some rows don't grow larger. I presume I need to call the tableview's -noteHeightOfRowsWithIndexesChanged for each row that has a height change. Is it okay to call this from within the tableView:heightForRow: method? No, it is not; you'll have to redo your logic, or call it with a range for all rows (probably the easiest thing to do). Thanks Corbin. What about from within the tableview delegate method - tableViewColumnDidResize ? That is fine; note that it is only sent out when the live-resize method ends. Your calculation in -heightForRow: can't depend on the - [tableColumn width], unless you call the -noteHeightXX method more frequently (ie: you'd have to capture when the setWidth: happens by subclassing the table column). I subclassed the table column and overrode its -setWidth method. When that is invoked, I recalculate the cell heights for *only* the visible rows. I keep track of those rows that change, prepare an index set, and notify the table view with -noteHeightXXX. Works like a charm! Question: presently, in the overridden -setWidth, I invoke - noteHeightXXX *before* calling [super setWidth:newWidth]As I said, this works, and seems to me to be the logical ordering of events, but just want to check if I should be calling -noteHeightXXX *after* invoking the super (NSTableColumn) -setWidth. ___ 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
initializer for NSTextView subclass not being invoked on Nib instantiation
I have a Nib with a single custom NSView subclass. That view has some controls in it, including an instance of an NSTextView (that is also subclassed). When the Nib is instantiated, the -awakeFromNib method of the MyTextView class is invoked, but neither -initWithFrame: nor - initWithFrame:textContainer: are invoked. These are the two documented initializers for a NSTextView, so I thought that one of them would be invoked. Googling this issue has led me to discover that, for NSTextView, - initWithCoder gets called instead. I've never run into this before -- that is, my subclassed NSView objects have their -initWithFrame: invoked (and NOT -initWithCoder). Is there something in the documentation that I can look for, for a class, that would help me know which way the Nib instantiation functionality will initialize (that is, -initWithCode versus designated initializer)? I am doing all my initialization of the instance in the -awakeFromNib method. This seems to work fine. Just curious if there's anything I need to be aware of/careful of in this case. ___ 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: initializer for NSTextView subclass not being invoked on Nib instantiation
Sure does cover it - quite specifically. Thanks for the reference -- lots of good material there that I need to absorb. On Apr 7, 2009, at 10:24 PM, Jonathan Hess wrote: Hey Stuart - This link should cover your questions: http://developer.apple.com/documentation/Cocoa/Conceptual/LoadingResources/CocoaNibs/CocoaNibs.html#/ /apple_ref/doc/uid/1051i-CH4-SW19 You're using awakeFromNib for its intended purpose. Good Luck - Jon Hess On Apr 8, 2009, at 1:15 AM, Stuart Malin wrote: I have a Nib with a single custom NSView subclass. That view has some controls in it, including an instance of an NSTextView (that is also subclassed). When the Nib is instantiated, the - awakeFromNib method of the MyTextView class is invoked, but neither -initWithFrame: nor -initWithFrame:textContainer: are invoked. These are the two documented initializers for a NSTextView, so I thought that one of them would be invoked. Googling this issue has led me to discover that, for NSTextView, - initWithCoder gets called instead. I've never run into this before -- that is, my subclassed NSView objects have their -initWithFrame: invoked (and NOT - initWithCoder). Is there something in the documentation that I can look for, for a class, that would help me know which way the Nib instantiation functionality will initialize (that is, -initWithCode versus designated initializer)? I am doing all my initialization of the instance in the - awakeFromNib method. This seems to work fine. Just curious if there's anything I need to be aware of/careful of in this case. ___ 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: initializer for NSTextView subclass not being invoked on Nib instantiation
Great explanation, Kyle. Thanks for taking the effort to provide one so thorough. On Apr 7, 2009, at 10:28 PM, Kyle Sluder wrote: On Wed, Apr 8, 2009 at 4:15 AM, Stuart Malin stu...@zhameesha.com wrote: Googling this issue has led me to discover that, for NSTextView, -initWithCoder gets called instead. Yes, indeed. I've never run into this before -- that is, my subclassed NSView objects have their -initWithFrame: invoked (and NOT -initWithCoder). Is there something in the documentation that I can look for, for a class, that would help me know which way the Nib instantiation functionality will initialize (that is, -initWithCode versus designated initializer)? It's helpful to know what's going on inside IB. When you drag an item from the library into your Nib, IB instantiates an object of that class, which is encoded into your Nib at save-time. At runtime, the framework decodes this object from the nib. This is why -initWithCoder: is being called; the object has already been initialized with -initWithFrame: when you dragged it into the document, now we're just reconstructing it from the archive. For instances of classes that are *not* in the palette, however, IB does something different. You typically drag an instance of one of the class's ancestors into your document -- for views, typically this is an NSView. But when you switch to the Identity pane of the Inspector and change the class identity, IB instead remembers to archive a little note saying this is not the class you're looking for. Instead you want this class. instead of the object itself. In the actual editor interface, IB continues using the instance you dragged out from the library, as it wouldn't be helpful for that to vanish. This is why -initWithFrame: is called for custom subclasses configured via the Identity pane; at runtime, the framework sees the little note saying go get an instance of this class instead, and does so. Since this isn't the instance that was freeze-dried into the Nib, the framework needs to construct an instance, hence calling the designated initializer -initWithFrame:. It can then configure all the properties that were archived in the nib, just like it does for Library-instantiated objects. Hope that helps, --Kyle Sluder ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: how to load an NSMenu out of a nib?
On Apr 8, 2009, at 2:10 PM, Peter Ammon wrote: On Apr 8, 2009, at 2:47 PM, Rua Haszard Morris wrote: I'm baffled, this seems fundamental, I can't see how it's done! I have a Menu in a nib file, which I need to use in a few places in code. So I want to do something like NSMenu* myMenu = [NSMenu menuFromNib:@MyNibFile name:@MyUsefulMenu]; Is this possible - how can this be done? I have looked at the NSMenu reference, how to unarchive Carbon menus (but there is no toll free mapping/other conversion between MenuRef and NSMenu?). It seems the only way to get this working is to have an class with an outlet specifically for receiving a reference to my menu - which seems indirect... Hopefully this is a dumb question and there's an easy answer... Making a class with an outlet, and passing an instance of that class as the nib's owner, is one way. You can also use the NSNibTopLevelObjects key as described at the bottom of http://developer.apple.com/DOCUMENTATION/Cocoa/Reference/ApplicationKit/Classes/NSNib_Class/Reference/Reference.html . You pass an NSMutableArray under this key, and after the nib is loaded, the array is populated with the top level objects in the nib. I do something similar, but not for a menu (I am doing this for a NSView). In my controller object's class initialization, I create a static instance of a Nib that I create multiple instances of (using NSNib's - initWithNibNamed). Then, whenever I need another instance of the Nib, I invoke -instantiateNibWithOwner:topLevelObjects on the static Nib instance. Doing so causes -awakeFromNib to be invoked for the controller (beside the Nib) because the controller is the Files Owner (set as an outlet in IB). If you do this, and your controller is also instantiated from a NIb, then you must be careful in your controller's -awakeFromNib to distinguish its initial awakening from subsequent calls where it is the File's Owner. btw: you can pass nil as the parameter for topLevelObjects: if you don't need the array of them (which I don't, as I do all the initialization of the instantiated Nib instance in the -awakeFromNib of the owner). ___ 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
NSString and decoding HTML Entities
I need to convert strings that contain HTML entities (e.g., #8217; or #gt;). I can't seem to find an NSString method to do so (not that I sometimes don't easily miss the obvious). So, I created a category on NSString and made two trivial methods that take advantage of toll- free bridging between NSString and CFStringRef by using CFXMLCreateStringByEscapingEntities and CFXMLCreateStringByUnescapingEntities. Is there a better way? ___ 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: NSString and decoding
On Apr 5, 2009, at 10:22 AM, Jack Carbaugh wrote: it would have helped if I read digested the WHOLE message. my apologies ! what i referenced and what he wanted were two different things. my apologies, jack no worries. this notion of escaping HTML entities seems often confused with URL encoding. ___ 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: NSString and decoding HTML Entities
On Apr 5, 2009, at 10:19 AM, I. Savant wrote: On Apr 5, 2009, at 3:56 PM, Stuart Malin wrote: I need to convert strings that contain HTML entities (e.g., #8217; or #gt;). To what? If you want it to be an attributed string, there's always the - [NSAttributedString initWithHTML:...] methods (in the NSAttributedString AppKit additions). If you just want to strip the HTML, you can then ask the attributed string for its -string ... The source is not HTML tagged, but contains HTML entities. see: http://www.w3schools.com/tags/ref_entities.asp http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references So, for instance, I want to convert --gt; to -- No need for an attributed string. ___ 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: NSString and decoding HTML Entities
On Apr 5, 2009, at 11:32 AM, I. Savant wrote: On Apr 5, 2009, at 4:35 PM, Stuart Malin wrote: The source is not HTML tagged, but contains HTML entities. see: http://www.w3schools.com/tags/ref_entities.asp http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references So, for instance, I want to convert --gt; to -- No need for an attributed string. Thanks, but I understand the difference perfectly, but it's irrelevant. HTML entities are HTML too, so this worked fine: NSMutableAttributedString * aStr = [[NSMutableAttributedString alloc] initWithHTML:[NSData dataWithContentsOfURL:[NSURL URLWithString:@file:///Users/me/test.html]] documentAttributes:nil]; [textView replaceCharactersInRange:NSMakeRange(0, [[textView string] length]) withString:[aStr string]]; ... with an HTML file containing the entity gt (NSData from local file for convenient illustrative purposes) but your method is probably more direct / efficient. I referenced the above because you said, I can't seem to find an NSString method to do so (not that I sometimes don't easily miss the obvious). It's not strictly NSString, but might have worked fine for you. Sorry, I.S., I didn't mean to imply that you didn't understand the difference -- just wanted to be clear for others following this thread as the distinction between percent escaping and entity decoding is often confused. Your point that HTML entities are HTML is sensible, and more important, valid. Thank you for taking the time to build a test case. The approach you have taken certainly offers much greater functionality, so I appreciate your posting this -- I may end up using it as well. ___ 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: Beachball on Lengthy Task
On Apr 4, 2009, at 5:07 PM, Andrew Farmer wrote: On 04 Apr 09, at 19:35, Pierce Freeman wrote: Yeah, it really helped! I am trying to get the contents of the files in a certain directory, so I think that I could probably get away with using a timer. I assume you mean NSTimer for the timer, though there could be another class that I am totally missing. ;) There's also NSObject's performSelector:withObject:afterDelay: method. And, if you are 10.5 only, there's also NSObject's performSelectorInBackground:withObject: http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/Reference/Reference.html#/ /apple_ref/doc/uid/2050-SW4 and make callbacks using - performSelectorOnMainThread:withObject:waitUntilDone: http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/Reference/Reference.html#/ /apple_ref/doc/uid/2050-CJBEHAEF Regarding threads, see Threading Programming Guide: http://developer.apple.com/documentation/Cocoa/Conceptual/Multithreading/ ___ 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: Beachball on Lengthy Task
On Apr 4, 2009, at 5:36 PM, Pierce Freeman wrote: And, if you are 10.5 only, there's also NSObject's performSelectorInBackground:withObject: Is this a timer or a thread creator? I don't believe it has inputs for the time, or could it just do it automatically? Also, is there some way I can make this work with a function already created? That is a thread creator. It will initiate the specified selector of the receiver (the invoked object). You can pass a single object to it; that object can, of course, contain references to other objects. Please be careful to distinguish method from function. If you meant an Objective-C method, yes, it will work with that. If you meant a C function, then no, it will not work, at least not directly, but in such case it would be easy to create a method that called the function. Note: as has already been pointed out, you must be very careful regarding thread safety. A background thread task must carefully constrain which objects it instantiates and methods used to those that are thread safe. Certainly no U/I. Read the cited references, and additional material germane to these. btw: by any stretch of the imagination, I'm not an expert with threads. ___ 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: Seeking advice on best practice for managing visibility of many subviews
On Apr 1, 2009, at 10:54 PM, Alexander Spohr wrote: Am 02.04.2009 um 04:47 schrieb Stuart Malin: I have a view that has hundreds of subviews. This sounds like a conceptual error. You could make something like cells instead of views, to avoid the NSView overhead. Arrange them in groups (NSArray/NSSet?) Then just don’t draw the groups you don’t want. Alas, I don't believe it is a conceptual error, just a complex U/I -- the many views that I am controlling the display of each have multiple sub views themselves as well as multiple controls... text, images, and buttons. The view I am managing is like a table (many rows) of the same basic sub view (display a variety of info, and having controls). ___ 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
Seeking advice on best practice for managing visibility of many subviews
I have a view that has hundreds of subviews. The user can control filters which causes different of the subviews to be presented; the collection of selected-for-presentation subviews are repositioned in the super view. I can think of two ways to handle this, and am not sure which is best: 1) remove and add subviews from the super view each time the filter criteria changes, or 2) leave all views in the super view, and just use -setHidden: to control whether presented or not. If the second approach is a better practice, does it matter where the hidden views are positioned? TIA. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
[NSView noob] How to be detect when a scroll view scrolls its document view
I have an NSScrollView with a document view that contains many subviews. I need to perform some processing on these views as they become visible or not visible because of scrolling of the ScrollView. I'm sure this must be straightforward to detect, but alas, I don't have a deep enough understanding of Views and ClipViews and ScrollViews. I've looked at the Cocoa Views Guide, and pertinent class documentation, but the requisite means have not been obvious to me. I've looked either for some kind of notification to register for, or a method to override. I have tried registering for the NSViewFramDidChangeNotification of the scroll view's clipView, but seem to only receive that on a resize, and not on scrolling. I suspect what I need to know is when the documentVisibleRect (or visibleRect) changes... I'd appreciate any pointers regarding what I should be looking at to devise a solution. TIA. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
[SOLVED] Re: Can NSTrackingArea rects be nested?
On Mar 28, 2009, at 2:31 AM, Quincey Morris wrote: On Mar 27, 2009, at 15:48, Stuart Malin wrote: I have a view that contains an NSTextView. I place NSTrackingAreas on portions of the TextView's text. I attach a userInfo dictionary to each of the tracking areas with a variety of parameters. The view containing the TextView happens also to have an NSTrackingArea around its entire frame. The NSTrackingAreaOptions are set to report mouse entered/exited for all of these tracking areas. When the mouse enters the outer (containing) view, *all* of the tracking areas report the event, even though the mouse has not entered any of the nested tracking areas. I thought perhaps I needed to do hit testing of the mouse's hit point to see if it was in the tracking area's rect. But this doesn't work, because the event's tracking area as reported by [[event trackingArea] rect] is, in all cases, the rect of the containing view. However, if I examine the content of the event's userData, it is associated with the distinct smaller, contained (nested) tracking areas. If [[event trackingArea] rect] is the rect of the containing view, then the actual behavior sounds correct (though not what you want, of course) -- if all the tracking areas have the same rect, they should all notify on the same mouse move. So the real question is why do they all have the same rect? You didn't by any chance specify the NSTrackingInVisibleRect option for them? Thanks Quincey -- I sure did have NSTrackingInVisibleRect set for the nested tracking areas (which, btw, do not have the same initializing rect). Removing NSTrackingInVisibleRect from the options fixed my problem -- which was more of a problem of me not fully understanding the description of the NSTrackingInVisibleRect option -- but in going back to the docs, they certainly do say that the visibleRect is returned (I just didn't get the implication of this). For clarity in the archival record: the problem I queried regarding has nothing to do with there being nested tracking areas. In fact, in trying to root this problem out, I had removed the outer containing tracking area and still was seeing the problem. As for NSTrackingInVisibleRect: I'm a bit mystified by its utility. I had though that what I was achieving by including this option was that the tracking area would not be triggered for parts of the rect that were visually occluded. However, it seems to function in quite a different way. ___ 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
Can NSTrackingArea rects be nested?
I have a view that contains an NSTextView. I place NSTrackingAreas on portions of the TextView's text. I attach a userInfo dictionary to each of the tracking areas with a variety of parameters. The view containing the TextView happens also to have an NSTrackingArea around its entire frame. The NSTrackingAreaOptions are set to report mouse entered/exited for all of these tracking areas. When the mouse enters the outer (containing) view, *all* of the tracking areas report the event, even though the mouse has not entered any of the nested tracking areas. I thought perhaps I needed to do hit testing of the mouse's hit point to see if it was in the tracking area's rect. But this doesn't work, because the event's tracking area as reported by [[event trackingArea] rect] is, in all cases, the rect of the containing view. However, if I examine the content of the event's userData, it is associated with the distinct smaller, contained (nested) tracking areas. I can't find much about this in the archives; I have read Quincey Morris's The NSTrackingArea Report but have not ferreted anything from it that sheds light on the situation I amencountering. Can NSTrackingArea support nested tracking areas? Des anything special need to be done? ___ 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
[SOLVED] Re: [noob] Best practice for creating multiple instances of a View
On Mar 20, 2009, at 11:08 AM, Stuart Malin wrote: On Mar 20, 2009, at 10:09 AM, mmalc Crawford wrote: Modulo other's comments about premature optimisation, if you want to avoid going back to the disk: http://developer.apple.com/DOCUMENTATION/Cocoa/Reference/ApplicationKit/Classes/NSNib_Class/Reference/Reference.html initWithNibNamed:bundle: instantiateNibWithOwner:topLevelObjects: Thanks mmalc. That looks to be the way to go: You may use this method to instantiate a nib file multiple times. As a follow-up, I've implemented code in this manner, and everything works just fine. As to whether it is more efficient or not, I've no idea. ___ 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
[noob] Best practice for creating multiple instances of a View
I have a Nib file containing a single NSView that contains several controls. I need to make numerous copies of this view (which are placed as subviews of some containing view). Presently, I load the Nib for each occurrence needed. But I now wonder if this is the best approach (going back to the Nib file and loading each time). Is there an alternative way to achieve this -- perhaps placing the target NSView in some other Nib container (such as with the controller and view that manage and contain the multiple instances of the target view) and somehow creating new instances? I have looked through the NSView reference material, and some of the Nib reference material, and don't see any obvious alternative. ___ 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: [noob] Best practice for creating multiple instances of a View
On Mar 20, 2009, at 8:38 AM, I. Savant wrote: On Fri, Mar 20, 2009 at 2:19 PM, Stuart Malin stu...@zhameesha.com wrote: I have a Nib file containing a single NSView that contains several controls. I need to make numerous copies of this view (which are placed as subviews of some containing view). Presently, I load the Nib for each occurrence needed. But I now wonder if this is the best approach (going back to the Nib file and loading each time). This is the usual way in Cocoa. If you're having performance issues, profile the code and address them specifically, but you're on the right track as far as the way it's normally done. Thanks for the quick reply and the assurance. No performance issues -- just had been wondering about the effect of going back to disk every time I need one of these views (which will be frequent and there will be many). Perhaps the fact of disk caching makes this a non issue. ___ 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: [noob] Best practice for creating multiple instances of a View
On Mar 20, 2009, at 9:30 AM, I. Savant wrote: On Fri, Mar 20, 2009 at 2:53 PM, Stuart Malin stu...@zhameesha.com wrote: Thanks for the quick reply and the assurance. No performance issues -- just had been wondering about the effect of going back to disk every time I need one of these views (which will be frequent and there will be many). Perhaps the fact of disk caching makes this a non issue. As Kyle stated and I implied - premature optimization. :-) Measure first, then optimize. As I recall (and I don't know if I recall correctly), I thought I heard that nib loading is pretty good about caching things, so I'd be surprised to see it hitting the disk each time, but it's not impossible, so ... measure then optimize. Appreciate the comments regarding premature optimization. I wasn't trying to optimize -- I had just been looking to validate that I was going about handling the situation the smartest way. Although nothing had appeared to me as more obvious or more efficient (referencing Kyle) -- it isn't always clear to us noobs when a non-obvious approach is available (and better). Thanks again for the comments -- I will be sure to remain with the proven approach I am pursuing :-) ___ 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: [noob] Best practice for creating multiple instances of a View
On Mar 20, 2009, at 10:09 AM, mmalc Crawford wrote: Modulo other's comments about premature optimisation, if you want to avoid going back to the disk: http://developer.apple.com/DOCUMENTATION/Cocoa/Reference/ApplicationKit/Classes/NSNib_Class/Reference/Reference.html initWithNibNamed:bundle: instantiateNibWithOwner:topLevelObjects: Thanks mmalc. That looks to be the way to go: You may use this method to instantiate a nib file multiple times. ___ 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: case-insensitive NSDictionary
On Mar 16, 2009, at 7:55 AM, Sherm Pendley sherm.pend...@gmail.com wrote: On Mon, Mar 16, 2009 at 12:03 PM, Michael Ash michael@gmail.com wrote: Why does everybody think that subclassing a class cluster is hard? Beats me - I've often wondered the same thing. All you need to do is implement the required primitive methods. What's so hard about that? Question from a non-expert: How does one know just which methods are required primitive methods for some class? Is that discernible from documentation? Header 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: Binding to selection of NSArrayController manually
On Mar 13, 2009, at 9:42 AM, Ivy Feraco wrote: I have an NSArrayController subclass and an NSPopUpButton subclass. I am trying to bind the NSPopUpButton's selected object to the selection of my array controller. I have to do this manually for reasons I won't get into here. But when I do this (self is myPopUpButton) [self bind:@selectedObject toObject:ArrayController withKeyPath:@selection options:nil]; I get the error that my array controller is not KVC for the key path selection. selection is definitely a controller key option in Interface Builder, is it possible that this doesn't work programmatically? Has anyone else run into this problem??? I want to bind to the selected object, not the index... so it seems my only option here is selectedObjects, which I will have to pass an array of one object to. I'm no expert in this area, but have dabbled with some code related to this, hence I offer the following subject to proviso... I believe the only KVObservable properties of NSArrayController that you can use in this way are: -selectedObjects, -selectionIndex, and - sectionIndexes. My suggestion, as you have subclassed NSArrayController, would be to add an additional KVO compliant property that returns the underlying (first) selected object (not the proxy object). Implement a - selectedObject property in your sub class and use it as the keyPath in the bind statement. - (id) selectedObject { return [[self selectedObjects] objectAtIndex:0]; } HTH. ___ 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: Is cascading Nib Loading from -awakeFromNib permissible?
On Mar 11, 2009, at 1:37 PM, Stuart Malin wrote: Further, the second Nib I am loading has no references back to the controller, except as File's Owner. And that's enough to get awakeFromNib'd. snip Interesting -- there must be some further distinctions here. I have another controller, not instantiated by being included in a Nib file, but by alloc init. This controller manages an ensemble of entities that are each loaded from (distinct) Nib files. This controller receives no calls to an -awakeFromNib method (I didn't have one there, but just put one there to see if it would receive calls for each Nib loaded). So, this scenario of receiving - awakeFromNib calls as a consequence of being some loaded nib's File's Owner seems to depend on just how the object invoking - loadNibNamed: was itslef invoked. For the record, I was mistaken. I must have done something incorrect when I tested this before. This other controller does in fact receive - awakeFromNib calls for each Nib it loads of which it is the File's Owner. Hence, there is no distinction between whether the controller itself had been loaded from a Nib or not. ___ 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
Is it possible to make the height of an NSSegmentedControl taller?
I am using an NSSegmentedControl in a toolbar to hold some mutually exclusive selections. I invoke -setImage:forSegment: to set an image for each, but the images are taller than the height of the segments. I don't seem to have any control over that height with the NSRect I use to init the segmented control. I have set the segmentStyle to NSSegmentCapsuleStyle, which provides a bit more height. I have tried scaling the images to fit (using -setImageScaling:forSegment) but then the images are too small. Is it possible to override something somewhere to affect the cells that are used? ___ 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
Is cascading Nib Loading from -awakeFromNib permissible?
In my MainMenu Nib I have a controller object. The code for that controller object has an -awakeFromNib method. That method invokes NSBundle's -loadNibNamed: method to load yet another Nib. Doing this leads to repeating invocations of the -awakeFromNib method of the initial controller (it is the same object, not new ones). Now, that leads me to think: just add an ivar flag that is set before invoking -loadNibNamed: so that a subsequent invocation of the controller's -awakeFromNib can ignore the secondary call. So I do this... and everything *appears* to work. But... I am concerned this may not be safe. Perhaps Nib loading is not re-entrant, even in the same thread. Question: Is what I am doing safe, dangerous, or does that not matter and my architecture/approach is not a good practice? ___ 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: Is cascading Nib Loading from -awakeFromNib permissible?
On Mar 11, 2009, at 12:37 PM, Dave Keck wrote: It looks like this is your answer: http://lists.apple.com/archives/cocoa-dev/2008/Apr/msg02276.html It sounds like the object is the file's owner of the nibs that you're loading using loadNibNamed:. Is this correct? Also check out: http://www.google.com/search?client=safarirls=en-usq=awakefromnib+called+twiceie=UTF-8oe=UTF-8 David Appreciate the links Dave, but these don't shed light on my situation (and, I had found these and others in queries before I posted to the list). I am getting infinite calls, not double calls. Further, the second Nib I am loading has no references back to the controller, except as File's Owner. I know this because to shed light on the situation, I am loading a Nib that I created in IB but added nothing to it nor changed any of its attributes or properties. ___ 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: Is cascading Nib Loading from -awakeFromNib permissible?
On Mar 11, 2009, at 1:03 PM, Ken Thomases wrote: On Mar 11, 2009, at 5:49 PM, Stuart Malin wrote: I am getting infinite calls, not double calls. It sounds to me like you're getting double calls and you're turning them into infinite calls. If you load a nib inside of - awakeFromNib, and you don't guard against being called again, you'll load the nib again, get -awakeFromNib again, load the nib again, ... infinitely. Ah, sure enough, because that re-invocation of my -awakeFromNib then invoked -loadNibNamed: which gets a circular mess in motion. My apologies to you, Dave, for not realizing this double call was in fact the issue. Further, the second Nib I am loading has no references back to the controller, except as File's Owner. And that's enough to get awakeFromNib'd. From the documentation for the awakeFromNib method: It is recommended that you maintain a one-to-one correspondence between your File’s Owner objects and their associated nib files. Loading two nib files with the same File’s Owner object causes that object’s awakeFromNib method being called twice, which could cause some data structures to be reinitialized in undesired ways. It is also recommended that you avoid loading other nib files from your awakeFromNib method implementation. http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Protocols/NSNibAwaking_Protocol/Reference/Reference.html So, you're going against Apple's recommendation in two ways. Sseems so. In regard to the first recommendation I am going against (one-to-one correspondence): Interesting -- there must be some further distinctions here. I have another controller, not instantiated by being included in a Nib file, but by alloc init. This controller manages an ensemble of entities that are each loaded from (distinct) Nib files. This controller receives no calls to an -awakeFromNib method (I didn't have one there, but just put one there to see if it would receive calls for each Nib loaded). So, this scenario of receiving -awakeFromNib calls as a consequence of being some loaded nib's File's Owner seems to depend on just how the object invoking -loadNibNamed: was itslef invoked. btw: I know that the IBOutlets in the controller associated with File's Owner that are linked in IB to objects there get over-written on loading of each Nib file. After loading each Nib, I copy the outlet values that I need, storing them in collection objects (happen to be using dictionaries). This controller works just fine, and handling the architecture this way allows me to have distinct Nibs rather than one rather cluttered Nib, (as each of the distinct Nibs has views and controllers of its own), yet all are managed by one in the same controller. In regards to the second recommendation I am going against (avoid loading nib files from awakeFromNib)): This is worded as a recommendation so, I'm presuming that if properly handled to avoid recursion and multiple initializations, then this is otherwise safe. I'm going to continue down this path as architecturally it works for me. I appreciate the quick replies, and the comments made do alert me to the effects I need to design around. Thanks again. ___ 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: [SOLVED] Re: NSArrayController -- will change selection?
On Mar 7, 2009, at 3:57 PM, Kyle Sluder wrote: On Sat, Mar 7, 2009 at 8:55 PM, Stuart Malin stu...@zhameesha.com wrote: Those are the only three means I am aware of (selection, window close, view change) that can potentially lead to loss of user data. Any others? Add and remove. You'd probably want to handle those conditions without involving the table view at all. Re: remove: Why ask for a decision about pending changes if the selected item is about to be removed? Instead, I display a remove confirmation sheet. The user can cancel that, and the pending changes remain pending. Also, must handle Quit of the application. ___ 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 intercept NSToolbar item selection changes
On Mar 9, 2009, at 3:46 AM, cocoa-dev-requ...@lists.apple.com wrote: On Sun, Mar 8, 2009 at 6:03 PM, Stuart Malin stu...@zhameesha.com wrote: I'm building a Preferences window that has a toolbar, in the style of Mail. I need to know if the user clicks on a toolbar item to change the pane. If the current pane has pending changes, I display a sheet asking for action regarding the present changes. I need to do this BEFORE the selected toolbar item is changed. Which means I need to intercept that change. Alas, I haven't been able to zero in on how to do that. I don't see NSToolBar delegate methods that provide such intercept (e.g. -(BOOL)shouldChangeToolbarItem or something of the like), nor do I see anything useful that I could override if I subclass the Toolbar instance. So, I must be overlooking something. If anyone can tell me what, I'd be eternally grateful :-) Â TIA. Could you simply reset the toolbar selection to whatever it was before, then display your sheet and then manually set the selection to the new one if the user agrees? I could do that, but then the user would see the selected toolbar item change away, then back. Mail's preference doesn't behave that way, so I am presuming there must be some way to intercept the change and stop it, if appropriate. Perhaps the way do handle this is to prevent redisplay of the window... I'll have to explore this... ___ 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 intercept NSToolbar item selection changes
On Mar 9, 2009, at 8:47 AM, Michael Ash wrote: On Mon, Mar 9, 2009 at 12:38 PM, Stuart Malin stu...@zhameesha.com wrote: On Mar 9, 2009, at 3:46 AM, cocoa-dev-requ...@lists.apple.com wrote: Could you simply reset the toolbar selection to whatever it was before, then display your sheet and then manually set the selection to the new one if the user agrees? I could do that, but then the user would see the selected toolbar item change away, then back. Mail's preference doesn't behave that way, so I am presuming there must be some way to intercept the change and stop it, if appropriate. Â Perhaps the way do handle this is to prevent redisplay of the window... I'll have to explore this... No need to prevent redisplay. Redisplay due to changes usually happens at the end of the event loop cycle where the changes took place. If you reset the selection before that happens (e.g. if the toolbar item's action fires before the redisplay) then the user will not see the intermediate state. Works like a charm! Thanks for the inisght, Michael. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: problem observing selectionIndex of an array controller
On Mar 7, 2009, at 10:10 PM, Ken Thomases wrote: On Mar 8, 2009, at 1:52 AM, Stuart Malin wrote: I'm trying to watch for changes in the selection of a tableView managed by an NSArrayController. I set up an observer: [mArrayController addObserver:self forKeyPath:@selectionIndex options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:NULL]; When the -observedValueForKeyPath:... method is invoked, the change dictionary has entries for the new and old value, but they are both NSNull. According to the NSArrayController docs, the selectionIndex is an observable property. Why might I not be getting the index values? Known bug. Search for (Missing) KVO notification old and new values at this page: http://homepage.mac.com/mmalc/CocoaExamples/controllers.html This bug will not be fixed in the forseeable future. You'll have to query the property for the new value and keep track of any old value yourself. Yes I will. Regards, Ken Thanks for the quick reply. ___ 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 intercept NSToolbar item selection changes
I'm building a Preferences window that has a toolbar, in the style of Mail. I need to know if the user clicks on a toolbar item to change the pane. If the current pane has pending changes, I display a sheet asking for action regarding the present changes. I need to do this BEFORE the selected toolbar item is changed. Which means I need to intercept that change. Alas, I haven't been able to zero in on how to do that. I don't see NSToolBar delegate methods that provide such intercept (e.g. -(BOOL)shouldChangeToolbarItem or something of the like), nor do I see anything useful that I could override if I subclass the Toolbar instance. So, I must be overlooking something. If anyone can tell me what, I'd be eternally grateful :-) TIA. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Can an object observe itself?
I have a model class with multiple properties. I need to know in a variety of places when certain of these change. Presently, the model objects can be changed by an inspector that has bindings to the model instances, which are managed as a collection by an NSArrayController. So... I tried adding code to the model object to observe itself (on a key that is a dependent key set up with +setKeys:triggerChangeNitificationsForDependentKeys). I was then going to have that observer issue a notification. However, the model's - observeValueForKeyPath:ofObject:change:context: method isn't getting called when I make changes. Thinking the problem was with the dependent key, I changed to observe a specific key. That doesn't work either. So I am wondering if an object can observe itself. I add the observer in the model object's -init method, after invoking -init on the superclass: - (id) init { self = [super init]; if (self != nil) { mRealName = nil; mUsername = nil; mPassword = nil; mFrequency = 15; [self addObserver:self forKeyPath:@password options:NSKeyValueObservingOptionOld context:NULL]; } return self; } Should this work, and my problem is elsewhere? To further isolate the problem, I made an explicit call to one of the - setKey methods of one of the model objects (i.e., bypassing the array controller). Still, I my observer was not triggered. ___ 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
[SOLVED} Re: Can an object observe itself?
Oops, found my problem... the model class is NSCoding compliant and so objects can also be initialized via -initWithCoder, and I needed to add the observer there as well. On Mar 7, 2009, at 10:31 AM, Stuart Malin wrote: I have a model class with multiple properties. I need to know in a variety of places when certain of these change. Presently, the model objects can be changed by an inspector that has bindings to the model instances, which are managed as a collection by an NSArrayController. So... I tried adding code to the model object to observe itself (on a key that is a dependent key set up with +setKeys:triggerChangeNitificationsForDependentKeys). I was then going to have that observer issue a notification. However, the model's -observeValueForKeyPath:ofObject:change:context: method isn't getting called when I make changes. Thinking the problem was with the dependent key, I changed to observe a specific key. That doesn't work either. So I am wondering if an object can observe itself. I add the observer in the model object's -init method, after invoking -init on the superclass: snip ___ 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: Can an object observe itself?
On Mar 7, 2009, at 11:18 AM, Keary Suska wrote: On Mar 7, 2009, at 1:31 PM, Stuart Malin wrote: I have a model class with multiple properties. I need to know in a variety of places when certain of these change. Presently, the model objects can be changed by an inspector that has bindings to the model instances, which are managed as a collection by an NSArrayController. So... I tried adding code to the model object to observe itself (on a key that is a dependent key set up with +setKeys:triggerChangeNitificationsForDependentKeys). I was then going to have that observer issue a notification. However, the model's -observeValueForKeyPath:ofObject:change:context: method isn't getting called when I make changes. Thinking the problem was with the dependent key, I changed to observe a specific key. That doesn't work either. So I am wondering if an object can observe itself. I add the observer in the model object's -init method, after invoking -init on the superclass: The main issue is that you have to remove observation before deallocating. Otherwise an exception will be raised (Leopard) or you will crash (Tiger and earlier). Yes, I do remove the observer in -dealloc. My problem was that I also created instances via NSCoding protocol methods (-initWithCoder) and had not there set the observer in place, and the source of my model objects was via that. Thanks for your help and interest! ___ 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
NSArrayController -- will change selection?
I've got a preferences view that is a kin to Mail's for its accounts, and I'd like it to behave the same. I am using an NSArrayController to manage a table list of accounts. There are a variety of account datum presented in NSTextFields. These fields are bound to the controller. I am able to track if changes to the presently selected account are made. Now, if the user changes the selection, I need to display an alert sheet asking if changes should be saved. That sheet needs to be presented *before* the selection is actually changed, because one of the alert sheet options (a la Mail) is Cancel. Alas, I am presently only able to detect that the array controller has changed the selection, not will change, and further have no way to prevent that change. I've been searching archives and reading documentation regarding to NSArrayController, but haven't some upon any insight into how to solve my problem. What I'd really like is to discover that the array controller has functionality similar to - (BOOL) willChangeSelection and -(void)DidChangeSelection. Does such exist and I've just missed it? ___ 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
[SOLVED] Re: NSArrayController -- will change selection?
Exactly what I need! Many thanks for responding. Can't believe I was acting as if having the array controller and a delegate were mutually exclusive. On Mar 7, 2009, at 3:12 PM, Kyle Sluder wrote: Wire up an object as your table view's delegate and implement -tableView:shouldSelectRow:. --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: [SOLVED] Re: NSArrayController -- will change selection?
On Mar 7, 2009, at 3:42 PM, Kyle Sluder wrote: Just be careful to cover all other methods by which the user can potentially lose data. No longer is your controller responding to a change in the selected model object, but instead to a change in the selected row in the view. It's unfortunate, but necessary in this circumstance. Yes -- I am also now trying to deal with an underlying window close as well. Am hooking in to the window's delegate method -windowShouldClose. And, since I have a toolbar in the prefs window, need also to intercept changes to the displayed view. Those are the only three means I am aware of (selection, window close, view change) that can potentially lead to loss of user data. Any others? ___ 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: [SOLVED] Re: NSArrayController -- will change selection?
On Mar 7, 2009, at 3:57 PM, Kyle Sluder wrote: On Sat, Mar 7, 2009 at 8:55 PM, Stuart Malin stu...@zhameesha.com wrote: Those are the only three means I am aware of (selection, window close, view change) that can potentially lead to loss of user data. Any others? Add and remove. You'd probably want to handle those conditions without involving the table view at all. Ah yes, those too. Thanks! A good smattering of code to write ___ 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: NSArrayController -- will change selection? -- tableView shouldSelectRow invoked twice
On Mar 7, 2009, at 3:12 PM, Kyle Sluder wrote: Wire up an object as your table view's delegate and implement -tableView:shouldSelectRow:. This delegate is being invoked twice. Is that ordinary and usual behavior? I found a post about this, made in 2005. Corbin Dunn replied that it was a subtle bug in the implementation of TableView, and would be fixed in a future release. Has it never been fixed? http://www.cocoabuilder.com/archive/message/cocoa/2005/12/7/152075 ___ 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
When to release an NSThread instance
I have a main thread method that allocates an NSThread object and inits with initWithTarget:selector:object. I then invoke the NSTask instance with -start. The specified selector is invoked, and there performs a background task that takes some time. When it is done, that method invokes a callback using performSelectorOnMainThread:withObject:waitUntilDone. That callback selector updates the applications U/I to reflect the outcome of the background task. After invoking the callback, the background task method cleans up, releases its autorelease pool, and then control reaches the end of the method. I am under the impression that having the method reach the end is sufficient to have the thread end. Is that correct? or do I need to invoke the thread instance with -exit ? Big question: how do I release the memory associated with the allocated task instance? I have two notions: 1) have the main thread callback autorelease the thread instance 2) have the thread autorelease itself at the end of the background task method after it invokes the callback (which is invokes with ...waitUntilDone:YES). I know I am treading in dangerous waters with threads... but the background activity can take many seconds, and I want the U/I responsive while the background activity is being performed. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
NSPopUPButton and selectedTag binding seems to give me index instead
I have a NSPopUpButton that is driven by bindings. I establish (programmatically) a binding between the NSPopUpButtom instance's selectedTag property and an NSTreeController that contains objects that have a property that should correspond with the available tag values. This does not seem to work. It appears that the binding is instead working with the popup button's index value. Symptoms and circumstance: 1) I changed the binding for the popup button's contentValues to refer to the tag property of the bound collection (rather than the title), and sure enough the proper tag values are displayed, so the menu items do have tag values. 2) When I change the popup button selection, the value in the object bound to the selectedTag is changed -- problem is: the value that is set is the index value, not the tag value. The code... First, what works: I drive the content and contentValues from an object that I construct which is an indexed accessor KVC (read-only) compliant with a backing store array of NSMenuItem items. When I initialize the collection, the menu items are initialized with a title. I also set the tag property. The bindings for these to the NSPopUpButton instance is done programmatically: [twitterUpdateFrequencyPopupButton bind:@content toObject:updateItems withKeyPath:@UpdateFrequencyMenuItems options:nil]; [twitterUpdateFrequencyPopupButton bind:@contentValues toObject:updateItems withKeyPath:@UpdateFrequencyMenuItems.tag options:nil]; updateItems is the ordered collection of NSMenuItems; its indexed accessor property is UpdateFrequencyMenuItems Here's what doesn't work, the binding for the selected tag value: [twitterUpdateFrequencyPopupButton bind:@selectedTag toObject:twitterAccountsArrayController withKeyPath:@selection.frequency options:nil]; twitterAccountsArrayController is an NSArrayController. The objects it manages have a frequency property. When this is run, I receive no messages in the console about anything bad or wrong. I've tried searching the usual places and with Marc Liyange's Mac Developer Search Engine for matters related to NSPopUpButton and selectedTag, but haven't found anything germane. So I post here. ___ 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: Checking for NULL (was Re: Can't get setDelegate to work...)
On Mar 4, 2009, at 12:15 PM, cocoa-dev-requ...@lists.apple.com wrote: In any case, and perhaps based purely on habit, I find it difficult to even write: NSStatusItem statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength] retain]; ...in favor of: NSStatusBar *systemBar = [NSStatusBar systemStatusBar]; if (systemBar != NULL) { AFAIU(nderstand): While nil and NULL may operate interchangeably (in most cases?), semantically, they are not the same thing. In your code fragment above, I believe most Cocoa programmers would expect to see: if (systemBar != nil) NULL is used more to indicate a null value c pointer. At one time I was under the impression they were defined differently: nil being of type id, and NULL being a void* But in trying to research this, I run across much conflicting info and suspect perhaps this has either changed over time, and/or depends on whether the use is in/with C++ or not. Perhaps some of the experts on this list can provide some clarity ___ 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
To run a block of code at every 1 second
On Mar 3, 2009, at 7:24 AM, cocoa-dev-requ...@lists.apple.com wrote: the following method is running in a separate thread: - (void)myFucntion { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; for (;;)// for loop starts here and is very quick, 100s of iterations per second { { // this block of code needs to be run at around 1 second interval // code here [appController performSelectorOnMainThread:@selector(updateProgress:) withObject:data waitUntilDone:YES]; } // other loop code here } [loop release]; } Not quite sure if I understand exactly your need, but perhaps this might be helpful: The following will delay for one second by sleeping the thread. Perhaps you could set the future date at the start of the loop block, and at the end, if the date is still in the future, sleep the thread. NSDate *future = [NSDate dateWithTimeIntervalSinceNow: 1.0f ]; [NSThread sleepUntilDate:future]; ___ 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: Why doesn't this work on my device?
offlist On Feb 27, 2009, at 8:27 AM, James Cicenia wrote: ARrrgh... The database exists but it contains nothing?! I double checked it in my trusty firefox sqlite extension, and everything is there. Is there some magic touch I need to do to get the tables properly into the device? I have cleaned my project, restarted xcode, rebuilt, etc. You may not be getting to your database file consistently. So while you see content when viewing the file directly, you may not actually be opening that file in your code. You really should/must use fileSystemRepresentation and not UTF8String. Someone wrote: if (sqlite3_open([path UTF8String], database) == SQLITE_OK) Don't use UTF8String to get a C string for a file system path, you should use -fileSystemRepresentation. I don't even know what that is? See: http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#/ /apple_ref/doc/uid/2154-fileSystemRepresentation I do my open this way: result = sqlite3_open([[self databaseFilePath] fileSystemRepresentation], mSqliteDatabase); And it works quite consistently and well. ___ 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
NSSplitView splitViewDidResizeSubviews
I have a Split View in my U/I. I want to update some controls *after* the user has repositioned the split view's divider. So, I implemented - (void)splitViewDidResizeSubviews:(NSNotification *)aNotification thinking it would be invoked after the user was done resizing (i.e., after the mouse up event). However, I receive this notification repeatedly while moving the divider. The same is true for: - (void)splitViewWillResizeSubviews:(NSNotification *)aNotification which also receives repeated notifications while the divider is moved. Is this expected/normal behavior for Will and Did notifications? (i.e. to be notified while the doing is happening and either at the outset and the conclusion )? If so, what then is the functional difference between Will... and Did... ? Also, if I want to know when the user has completed the divider movement, how would I find that out? I suspect I'd need to subclass NSSplitView method that handles the mouse events... ___ 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
OutlineView with custom TableColumn cell doesn't redisplay when losing focus
I have a custom cell attached to a TableColumn of an OutlineView. My delegate for the OV implements willDisplay:cell: I need to redisplay all cells when the OV loses or gains focus, but this method seems only to be called for the highlighted row. Is there some property I need to activate for the OV so that all visible cells are updated when the OV loses focus (and conversely, when it regains focus)? ___ 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 Custom Background ...
On Feb 25, 2009, at 2:22 PM, Corbin Dunn wrote: On Feb 25, 2009, at 2:58 PM, Mic Pringle wrote: Hi, I've a subclass of NSTableView that draws a custom gradient background. What I'd like to do now is to draw a slightly different background when the window containing the custom NSTableView loses focus. Is this possible ? If so, could someone please point me in the right direction ? I know that in the NSTableView subclass you can use [self window] to get the containing window, so I have tried things like [[self window] isKeyWindow] and [[self window] isMainWindow] but this doesn't seem to get me anywhere. In addition to what Nick said, you probably aren't invalidating the tableview when the window looses/gains key status. What you want to do does work, and is possible; the NSTableViewSourceListHighlightStyle does this automatically. I believe that attribute is: NSTableViewSelectionHighlightStyleSourceList, and is set by invoking: [tableObject setSelectionHighlightStyle :NSTableViewSelectionHighlightStyleSourceList]; ___ 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: OutlineView with custom TableColumn cell doesn't redisplay when losing focus
On Feb 26, 2009, at 10:33 AM, Kyle Sluder wrote: What is focus? Do you mean when the outline view becomes key, or when the window becomes key, or something else? --Kyle Sluder I meant that the view becomes key. I used the term focus because a focus ring gets (well, may get) drawn. And because that was the term used in some sample code I was looking at, which had this line (which is in a cell's -drawInteriorWithFrame:inView: method): BOOL isViewInFocus = self controlView] window] firstResponder] isEqual:[self controlView]]; Is there perhaps a better way to determine if a view is key ? ~~~ What my post concerned is that when some other view becomes key from the OutlineView having been key, the OV delegate receives a outlineView:willDisplayCell:forTableColumn:item: message -- but only for an item that is highlighted. I wanted to find a way to update all the visible rows. ___ 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
Drawing a badge in an OutlineView column cell: but width changes on expanding
I have been reading various blogs, tried to search CocoaBuilder, and have ben looking at the code in Apple's PhotoSearch sample, but am not clear about the best way to handle this situation: I have an NSOutlineView for which I have set a custom cell (sub class of NSTextViewCell) in order to draw a badge on the right side of the cell. I have overridden drawInteriorWithFrame:controlView: to do my drawing there. It seems to me that when a row that has descendent nodes is expanded, the width of the hierarchically containing cells (lower level value) are made wider (by the same amount as the indentation). Both the indented cells (by their indentation) and the higher order cells (by the increased cell width) now have their right side pushed partway out of the viewable area of the column. So, I can't determine the x position of the badge based upon the width of the cell (a hierarchically outer cell with no indent has an increased width, yet to calculate a proper x coordinate, the cell would need to know that some other table items are expanded; how could it know this?) My best idea so far is to determine the position based on the table column's width, and take into account the indent level. But I suspect there are any of a number of ways to handle this, and so am looking for guidance on a best practice from those with experience. TIA. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Drawing a badge in an OutlineView column cell: but width changes on expanding
On Feb 24, 2009, at 10:51 AM, Corbin Dunn wrote: On Feb 24, 2009, at 12:38 PM, Stuart Malin wrote: I have been reading various blogs, tried to search CocoaBuilder, and have ben looking at the code in Apple's PhotoSearch sample, but am not clear about the best way to handle this situation: I have an NSOutlineView for which I have set a custom cell (sub class of NSTextViewCell) in order to draw a badge on the right side of the cell. I have overridden drawInteriorWithFrame:controlView: to do my drawing there. It seems to me that when a row that has descendent nodes is expanded, the width of the hierarchically containing cells (lower level value) are made wider (by the same amount as the indentation). Both the indented cells (by their indentation) and the higher order cells (by the increased cell width) now have their right side pushed partway out of the viewable area of the column. So, I can't determine the x position of the badge based upon the width of the cell (a hierarchically outer cell with no indent has an increased width, yet to calculate a proper x coordinate, the cell would need to know that some other table items are expanded; how could it know this?) My best idea so far is to determine the position based on the table column's width, and take into account the indent level. But I suspect there are any of a number of ways to handle this, and so am looking for guidance on a best practice from those with experience. TIA. You should just draw the badge in -drawInteriorWithFrame, and everything should work provided you are right-aligning it with the frame passed to you. What does your code look like? Maybe it has some errors/problems. Thanks for replying so quickly, Corbin. My code for drawing the badge is relatively straightforward. But... to get a handle on the problem, I am not presently drawing it. I have greatly simplified my code, and all ll I do now is: 1) in the -init for the cell, I set -setBordered So I can see the size of the cell. - (id) init { self = [super init]; if (self != nil) { [self setLineBreakMode:NSLineBreakByTruncatingTail]; [self setBordered:YES]; 2) and I have trivialized -drawInteriorWithFrame - (void)drawInteriorWithFrame:(NSRect)cellFrame inView: (NSView*)controlView { [super drawInteriorWithFrame:cellFrame inView:controlView]; return; 3) When I run, I get what I consider to be weird behavior: a) When the app first starts and displays, the borders of the level 0 entries (none are expanded) are completely visible. b) when I expand a level 0 item, the borders for all cells (level 0 and level 1) are no longer visible on the right side. c) the OutlineView is in a splitter. If I move the splitter to expand the outline view's width, when I release, the right side of the cell borders are all visible (both level 0 and level 1 items), and are nearly flush to the right side of the column. Nice. d) If I then collapse the expanded item, all of the cells borders are visible, but the cell width is noticeably smaller than the column's width. I've just published a blog that has screen shots of these states: http://stuartmalin.blogspot.com/2009/02/troubles-with-cocoa-custom.html So, what I am seeing is that the cell's width fluctuates inconsistently with respect to the column's width, sometimes being nicely bound to the column's right side, sometimes extending beyond, and sometimes being too short. I am on Leopard 10.5.6 using Xcode 3.1.1; Target: Base SDK = Mac OS 10.5 ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Binding an OutlineView and/or its TableColumn to a TreeController
I have a data model that is bound to a TreeController. The TreeController manages an OutlineView. When I first implemented this, I bound the TableColumn backing the OutlineView to the TreeController (the TableColumn's Value property to the TreeController's arrangedObjects with a Model Key Path for the property I want displayed). This worked fine -- even though I did not bind the OutlineView in any way to the Tree Controller. In some sample code I have been looking at, the Content property and the Selected Index Paths property of the OutlineView are bound to the TreeController (arrangedObjects and selectedIndexPaths, respectivel); this is in addition to the TableColumn's bindings. I am not sure what, if any, functionality I am losing by *not* binding the OutlineView as well. (It seems to work just fine, expanding and collapsing tree nodes). Question 1: Is it necessary to bind both the OutlineView and the TableColumn? I can also make this work in the converse: binding the OutLineView's Content property and *not* binding the TableColum's Value. Well, almost works as no data is actually displayed. But that is overcome because (for other reasons) I use a custom cell for the TableColumn. I've got a controller that is the delegate for the OutlineView, and it implements: - (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(NSCell*)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item When this delegate method is invoked, I call -setStringValue on the cell (with data gotten from the represented item), thereby setting its value, which is properly displayed. Question 2: is this a valid approach (that is, bind only the OutlineView's Content property and supply the text via the delegate method)? I ask because while this does work, I don't know what gotchas may be lurking that I have not yet stumbled upon. ___ 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
Memory Management and @synthesized accessors
I've seen the idiom [[property retain] autorelease] used in getter accessors, and just re-read the Memory Management Programming Guide (MMPG) to understand this. Now I do, and see how the perhaps once canonical approach of having a setter release-then-retain (if the new value is not equal to the present value) can lead to references persisting to a released object (e.g., if the setter is invoked after the getter has issued references). In fact, the MMPG goes so far as to say this about this approach: ...because of the potential dangers of invalidating objects prematurely, use of this technique should be used sparingly and well documented. So, I am curious as to why the default (retain) behavior of @synthesize does just this? And, is there a way to tell @synthesize to use one of the other approaches, or do I need to make such a property @dynamic and handle the setter/getter myself? ___ 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