Say I have a class called ExampleClass
.
Say I then write code like so:
@objc class ExampleClass: NSObject {}
With an ObjectiveC file header like so:
#import <Foundation/Foundation.h>
#import <React/RCTBridgeModule.h>
@interface RCT_EXTERN_MODULE(ExampleClass, NSObject)
@end
Which I then consume in my React Native app like so:
console.log('exampleClass', React.NativeModules.ExampleClass);
Now compiling with react-native run-ios
produces the following exceptions:
❌ Undefined symbols for architecture x86_64
> Symbol: `_OBJC_CLASS_$_ExampleClass`
> Referenced from: `l_OBJC_$_CATEGORY_ExampleClass_$_RCTExternModule in ExampleClass-2517576D7E90370.o
❌ ld: symbol(s) not found for architecture x86_64
❌ clang: error: linker command failed with exit code 1 (use -v to see invocation)
** BUILD FAILED **
While changing only the swift so that it reads:
@objc(ExampleClass)
class ExampleClass: NSObject {}
results in successful compilation. What is the difference between those two syntaxes? Why is the latter working while the former is not?