NSObjectFromString ... Any way to do this?

So Objective-C has these wonderful functions NSClassFromString()and NSProtocolFromString()that return a class or protocol from the passed string name. Is there a way to do this using an object?

+3
source share
3 answers

No, because objects do not have canonical names or string representations. With the class, there is either a class called "NSWindow" or not. With objects this correspondence does not apply. If you want to serialize an object, see the NSCoding protocol and related documentation .

+5
source

, , - -description, , , . , , /.

0

If you want to instantiate an object, you can also do this

Class class = NSClassFromString(className);
id object = [class new];
0
source

Source: https://habr.com/ru/post/1729501/


All Articles