On Jun 19, 2015, at 3:20 PM, Jens Alfke <jens@mooseyard.com> wrote:The Obj-C runtime type info for property types appears to omit the module names of Swift classes. For instance, if there's a Swift class "Foo" (inheriting from NSObject) in module "MyApp"; and some class has a property whose type is Foo*, then according to the runtime the property's type is "Foo", not "MyApp.Foo".
More specifically, the string returned by property_getAttributes( ) is something like:
T@"Foo",N,D,&
when it should be
T@"MyApp.Foo",N,D,&
This breaks code of mine that looks up the property's class based on the class name parsed from the above — when it calls objc_getClass("Foo") it gets NULL.
I'm working around this by looking at the name of the class that contains the property, checking if it includes a module (a prefix delimited by "."), and if so prepending that module name to the property's class; if this fails then I fall back to looking up the class in the global namespace.
This works, but it's kind of a kludge. It can do the wrong thing if a module contains a class with the same base name as one in the global namespace, and it'll also fail if a class in one module has a property whose type is a class from a different module. However, I can't see a proper fix for this since the module information does not seem to be available through the runtime API.
Is there a way to get the full class name, or should I file a Radar?
- Doug
No comments:
Post a Comment