我正在尝试加载可加载包。代码如下。
NSString *fullPath = @"/Users/xyz/Desktop/MyPlugin.bundle"; // Assume this exists.
NSBundle *bundle;
Class principalClass;
id instance;
bundle = [NSBundle bundleWithPath:fullPath];
// Read Principal class
principalClass = [bundle principalClass];
instance = [[principalClass alloc] init];
如何获取/设置实例类中的属性? instance
是 id 类型,它不知道包的类名。
最佳答案
您可以使用 KVC 设置/获取属性,并且可以在对对象调用 performSelector
之前使用 respondsToSelector
探测对象。
但这并不理想,通常您应该知道主要类是什么,从而了解可以用它做什么。
最后,这个可加载包提供了 .framework
没有提供的什么功能?
关于objective-c - Cocoa 中的可加载包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31285736/