Mac Deprecated [NSSavePanel filename]

Senor Cuete

macrumors 6502
Original poster
Nov 9, 2011
281
12
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:
– initWithContentsOfURL: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].
 

gnasher729

macrumors P6
Nov 25, 2005
16,532
3,131
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.
 

Sydde

macrumors 68020
Aug 17, 2009
2,107
2,294
IOKWARDI
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.