Re: Xcode 6 does not warn on use of iOS8 only method when deployment target is iOS7
Re: Xcode 6 does not warn on use of iOS8 only method when deployment target is iOS7
- Subject: Re: Xcode 6 does not warn on use of iOS8 only method when deployment target is iOS7
- From: Ken Thomases <email@hidden>
- Date: Sat, 27 Sep 2014 00:01:29 -0500
On Sep 26, 2014, at 9:51 AM, Fritz Anderson <email@hidden> wrote:
> On 26 Sep 2014, at 8:27 AM, David Hoerl <email@hidden> wrote:
>
>> I have a fairly strong recollection that I **use** to get warned if I tried to use a new API method when the Deployment target was set to an older release.
>>
>> I tested my app on iOS8, worked fine, crashed in QA - turns out I inadvertantly pulled in a newer method on NSString (I guessed at a name, command completion filled it in for me).
>>
>> // From CMD-click - (BOOL)containsString:(NSString *)aString NS_AVAILABLE(10_10, 8_0);
>> NSString *foo = @"FOO";
>> if([foo containsString:@"OO"]) {
>> NSLog(@"WOW");
>> }
>>
>> Xcode 6 and 6.1 compile this just fine, no error or warning. I entered rdar://18459505, but hoping that someone can tell me the error of my ways, and what magic option that when set re-enables the old behavior.
>
> The painful summary is “works as intended.” For quite some time, developer tools have silently passed all API from the latest release of Apple’s operating systems, and I know of no way to turn that off. (I’ve searched the Build Settings for “API,” “unimplemented,” and “target.”)
I found this via StackOverflow:
https://github.com/mattjgalloway/MJGFoundation/blob/master/Source/Utilities/MJGAvailability.h
It's a gross hack. It's not as good as an official mechanism. It's fragile in the face of future changes to the availability macros. But it works.
Personally, I think detecting uses of APIs newer than the deployment target would be a good feature for the static analyzer. That is, it could even work in the case of intentional uses of new APIs so long as they were properly protected by runtime checks for availability, because analyzing code paths is what the static analyzer does. It would "know" that -respondsToSelector: and the like would return false when the API is not available, so uses protected by such a check would be fine, but uses without proper checking would be flagged.
Regards,
Ken
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden