Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
您可以使用以下代码创建类引用:
Class M = [NSMutableString class]; // NSMutableString (for example).
然后,您可以使用如下代码调用该已保存类的方法:
[M string];
但是你能从那个类名创建实例吗(我知道下面的行不通)?
M *newInstance;
您可以像这样分配类的新实例
id instance = [[M alloc] init];
+alloc是一个类方法,就像string在你的例子中一样,所以规则是一样的。
+alloc
string