Using Constants with Crash Weak Link Extern Constants

I am trying to use the Cocoa framework inside a plugin (NSBundle) as a loosely coupled structure, so I can use it in several plugins. I have a source for the framework, and I have successfully used the framework in another plugin, although not as a loosely coupled structure. In this case, it works well.

This works, but when I try to use the extern * const property when setting up aspects of the framework from my code, the application crashes with the following error:

Exception Type: EXC_BAD_ACCESS (SIGBUS) Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000000000000 

An example of a constant declared in the framework:

 Class.h extern NSString * const AConstant; 

And implementation:

 Class.m NSString *const AConstant = @"someString"; 

The code in my application causing the error:

 NSLog(@"%@", AConstant); 

The frame is loading - if I'm not trying to use constants, it works as expected. I can also configure it using the constant value manually, i.e.

 [framework setConfig:@"someString"] 

Instead of what I prefer to use:

 [framework setConfig:AConstant] 

As stated above, I can change the structure if necessary.

Does anyone have any advice on what I can do to make this infrastructure work as weak fragmentation?

+4
source share
1 answer

I'm not sure about your infrastructure problem, but you can get around your problem by declaring a line only in the header files, for example:

 __unused static NSString *const AConstant = @"someString"; 

The __unused stops the compiler warning that a constant is not used by every file containing the header. The only problem is that you have to use the correct comparisons [string isEqual: AConstant] , pointer comparisons will not work.

+1
source

All Articles