gpt4 book ai didi

objective-c - Cocoa 中的可加载包

转载 作者:行者123 更新时间:2023-12-03 17:02:08 24 4
gpt4 key购买 nike

我正在尝试加载可加载包。代码如下。

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com