NSClassFromString returns nil

后端 未结 7 1571
礼貌的吻别
礼貌的吻别 2020-12-09 04:28

Why does NSClassFromString return nil ? As per the definition it has to return class name. How should I take care to rectify this problem? I need t

7条回答
  •  一生所求
    2020-12-09 05:08

    The Documentation for the function says:

    Return Value The class object named by aClassName, or nil if no class by that name is currently loaded. If aClassName is nil, returns nil.

    An example of how this should be properly used is as follows:

    Class dictionaryClass = NSClassFromString(@"NSMutableDictionary");
    id object = [[dictionaryClass alloc] init];
    [object setObject:@"Foo" forKey:@"Bar"];
    

提交回复
热议问题