Ale*_*lan 12 theory oop class objective-c instances
您可以使用以下代码创建类引用:
Class M = [NSMutableString class]; // NSMutableString (for example).
Run Code Online (Sandbox Code Playgroud)
然后,您可以使用以下代码调用该已保存类的方法:
[M string];
Run Code Online (Sandbox Code Playgroud)
但是你可以从该类名创建实例(我知道以下不起作用)?
M *newInstance;
Run Code Online (Sandbox Code Playgroud)
Joe*_*Joe 17
您可以像这样分配类的新实例
id instance = [[M alloc] init];
Run Code Online (Sandbox Code Playgroud)
+alloc是一个类方法,就像string在您的示例中一样,因此规则是相同的.