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?
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
Try setting the base SDK to 10.6 and the deployment target to 10.5.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With