In 10.6, Apple added +[NSPropertyListSerialization dataWithPropertyList:format:options:error:] and is marked as old +[NSPropertyListSerialization dataFromPropertyList:format:errorDescription:] as deprecated and soon deprecated. One way to use the new call on 10.6 and above and still run on earlier versions of the OS would look something like this:
if ([NSPropertyListSerialization respondsToSelector:@selector(dataWithPropertyList:format:options:error:)]) { data = [NSPropertyListSerialization dataWithPropertyList:dict format:NSPropertyListXMLFormat_v1_0 options:0 error:&err]; } else { data = [NSPropertyListSerialization dataFromPropertyList:dict format:NSPropertyListXMLFormat_v1_0 errorDescription:&errorDescription]; }
Built against the 10.4 SDK (for compatibility with this version), this leads to: warning: 'NSPropertyListSerialization' may not respond to '+dataWithPropertyList:format:options:error:' And even worse, since the compiler does not know about this selector, it may pass arguments incorrectly.
Is NSInvocation an approved / best way to call new APIs that do not yet exist with respect to the SDKs?
source share