Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Portable code for deprecated userInfo dictionary key (Cocoa)

In Mac OSX 10.6, the NSErrorFailingURLStringKey userInfo dictionary key is deprecated in favor of NSURLErrorFailingURLStringErrorKey. I am trying to write my program to be portable to both Mac OSX 10.5 and 10.6. For the time being, I'm just using the old key--but my compiler is giving me annoying deprecated warnings.

// The following causes deprecation warnings
[[error userInfo] objectForKey:NSErrorFailingURLStringKey]

// But this one won't work on OSX 10.5
[[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]

What is the best way to write portable code to handle deprecated userInfo dictionary keys?

like image 247
Nate Thorn Avatar asked Jul 06 '10 21:07

Nate Thorn


2 Answers

You can use preprocessor directives like so:

#if defined(MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
    [[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]
#else
    [[error userInfo] objectForKey:NSErrorFailingURLStringKey]
#endif
like image 117
Tom Dalling Avatar answered Nov 15 '22 06:11

Tom Dalling


Try setting the base SDK to 10.6 and the deployment target to 10.5.

like image 42
JeremyP Avatar answered Nov 15 '22 05:11

JeremyP