Xcode 7 Analyzer Fails to Recognize Method call on Dynamically-generated Class Object

Originator:justatheory
Number:rdar://21488883 Date Originated:2015-06-22
Status:Open Resolved:
Product:Xcode Product Version:7.0 beta (7A120f)
Classification:Developer Tools Reproducible:Always
 
Summary:
I have code like this in a class that has been working great on in Xcode 6 and earlier:

    id lm = NSClassFromString(@"CLLocationManager");
    if (lm && [lm locationServicesEnabled]) { … }

Xcode 7 reports this as deprecated with this message:

'locationServicesEnabled' is deprecated: first deprecated in iOS 4.0

However, that deprecation is for the locationServicesEnabled instance property, but this code is calling the +locationServicesEnabled class method, which is *not* deprecated.

Steps to Reproduce:
1. Paste this code into an app:

    id lm = NSClassFromString(@"CLLocationManager");
    if (lm && [lm locationServicesEnabled]) NSLog(@"YES");

2. Build the app.


Expected Results:
No warnings.

Actual Results:
Got warning:

  'locationServicesEnabled' is deprecated: first deprecated in iOS 4.0

Version:
Version 7.0 beta (7A120f)

Notes:


Configuration:
Occurs in Xcode 7 beta 1 (7A120f), but not Xcode 6 or earlier.

Attachments:

Comments

David Wheeler 07-Jul-2015 10:56 AM

So then I can call CLLocationManager class methods on lm?

Class lm = NSClassFromString(@"CLLocationManager");
return lm && [lm locationServicesEnabled];

I would not have expected that, since locationServicesEnabled is a class method on CLLocationManager, not on Class.

By justatheory at July 7, 2015, 5:56 p.m. (reply...)

Apple Developer Relations 29-Jun-2015 03:15 PM

Hello David,

This is a follow-up regarding regarding Bug ID# 21488883.

This issue behaves as intended based on the following:

You call 'locationServicesEnabled' on 'id', so does a global lookup assumes that 'id' is likely an instance of CLLocationManager. Since you know you are getting a Class object and not an instance, change the code to:

Class lm = NSClassFromString(@"CLLocationManager");

Please update your bug report to let us know if this is still an issue for you.

By justatheory at July 7, 2015, 5:43 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!