使用弱相关框架的extern常量Crash [英] Using Weakly Linked Framework's extern constants Crash
问题描述
我试图在插件(NSBundle)中使用Cocoa框架作为弱链接框架,以便我可以在多个插件中使用它。我有框架的源,并已成功地使用框架在另一个插件,虽然不是一个弱链接的框架。
I'm attempting to use a Cocoa framework inside a plugin (NSBundle) as a weakly-linked framework, so that I can use it in multiple plugins. I have the source for the framework, and have used the framework successfully in another plugin, albeit not as a weakly linked framework. In that case it works well.
它的工作原理,但是当我在我的代码中配置框架的方面尝试使用extern * const属性时,应用崩溃出现以下错误:
It works, but when I attempt to use an extern *const property when configuring aspects of the framework from within my code, the app crashes with the following error:
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000000000000
在框架中声明的常量示例:
An example of the constant as declared in the framework:
Class.h
extern NSString * const AConstant;
而实施:
Class.m
NSString *const AConstant = @"someString";
在我的应用程序中导致错误的代码:
Code within my app that causes the error:
NSLog(@"%@", AConstant);
正在加载框架 - 如果我不尝试使用常量。我还可以手动使用常量的值配置它,即
The framework is loading - if I do not attempt to use the constants it works as expected. I can also configure it by using the value of the constants manually, i.e.
[framework setConfig:@"someString"]
而不是我更喜欢使用:
[framework setConfig:AConstant]
如上所述,我可以修改框架如果必要。
As alluded to above, I am able to modify the framework if necessary.
有没有人有什么我可以做什么,让这个框架作为weak_framework运行?
Does anyone have any tips on what I could do to get this framework running as a weak_framework?
推荐答案
我不知道你的框架问题,但你可以解决你的问题,只通过声明头文件中的字符串,像这样:
I'm not sure about your framework issue, but you could work around your problem by declaring the string only in the header files, like this:
__unused static NSString *const AConstant = @"someString";
__未使用
关键字停止编译器警告该常量不被包括头的每个文件使用。唯一的问题是,你必须使用适当的 [string isEqual:AConstant]
比较,指针比较将无法工作。
The __unused
keyword stops the compiler warning that the constant is not used by every file that includes the header. The only problem being that you'll have to use proper [string isEqual: AConstant]
comparisons, pointer comparisons won't work.
这篇关于使用弱相关框架的extern常量Crash的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!