views:

102

answers:

2

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?

+1  A: 

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

JeremyP
+1  A: 

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
Tom Dalling
That's what I was looking for, thanks!
Nate Thorn

related questions