So Objective-C has these nice functions NSClassFromString()
and NSProtocolFromString()
, which return a class or protocol from a passed string name. Is there any way to do this with an object?
views:
66answers:
2
+3
A:
No, because objects don't have canonical names or string representations. With a class, there either is a class called "NSWindow" or there isn't. With objects, that correspondence doesn't really apply. If you're looking to serialize an object, check out the NSCoding protocol and accompanying documentation.
Chuck
2010-01-22 02:05:32
+1, I suspect you're closer to the OP's intent than I.
John Rudy
2010-01-22 02:19:47
A:
The closest thing I can think of is -description
, but I suspect you're looking more for introspection into all the members than the basic description. If you are, you're going with Chuck's answer, because you need to serialize/deserialize.
John Rudy
2010-01-22 02:19:05