Deprecated [NSSavePanel filename]

Discussion in 'Mac Programming' started by Senor Cuete, Mar 14, 2012.

  1. Senor Cuete macrumors regular

    Nov 9, 2011
    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].
  2. JoshDC macrumors regular

    Apr 8, 2009
    Isn't NSURL's instance method "path" what you want?
  3. Senor Cuete thread starter macrumors regular

    Nov 9, 2011
  4. gnasher729 macrumors P6


    Nov 25, 2005
    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.
  5. Sydde macrumors 68020


    Aug 17, 2009
    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.

Share This Page