View Full Version : Deprecated [NSSavePanel filename]

Senor Cuete
Mar 14, 2012, 06:06 PM
I've finally had to "upgrade" to OS X 10.7 (which I REALLY HATE). Some of the object methods in my code have been deprecated. One that is used in my code to save data in files is:

[NSSavePanel* filename];

According to the Documentation you should use [NSSavePanel URL] instead. A lot of objects can use a URL instead of an NSString - for example [NSImage writeToURL: atomically:];

One method that still needs an NSString is the NSKeyedArchiver method
archiveRootObject:toFile: - file is an NSString.

Theoretically one could get the NSSavePanel's URL using [NSSavePanel URL] and then get an NSString using some NSString method like

+ stringWithContentsOfURL:usedEncoding:error:

For some reason these return a nil NSString and error looks like an NSCocoaDomainError, code 260.

Perhaps one of you could suggest how I might continue to use archiveRootObject:toFile: without relying on the deprecated method [NSSavePanel filename].

Mar 14, 2012, 07:42 PM
Isn't NSURL's instance method "path" what you want?

Senor Cuete
Mar 15, 2012, 08:44 AM

Mar 15, 2012, 12:23 PM
It might not be a file. The URL might point to some server in the cloud, or it might point to some server in the cloud when the user runs your app in 10.8 or 10.9. There's probably a reason why it's deprecated.

Mar 16, 2012, 02:19 AM
I would suggest you use -archivedDataWithRootObject: to get a NSData object, then use one of the NSData methods that writes to a URL. This URL scheme was on the horizon with Leopard, steadily approaching like some kind of large feline, you need to get used to it.