Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use constructor attribute instead of +load objc method (facebook#24155)
Summary: Xcode 10.2 forbids creating categories for swift class that uses `+load` method. In react-native categories like this are used to register swift classes as modules (macro `RCT_EXTERN_MODULE`) This PR changes it to use `__attribute__((constructor))` instead of objc `+load` method. I introduced new macro for this purpose, `RCT_EXPORT_MODULE_NO_LOAD`, it expands in something like: ``` void RCTRegisterModule(Class); + (NSString *)moduleName { return @"jsNameFoo"; } __attribute__((constructor)) static void initialize_ObjcClassFoo{ RCTRegisterModule([ObjcClassFoo class]); } ``` Functions marked with `__attribute__((constructor))` are run before main and after all `+load` methods, so it seems like correct thing to do. Fixes facebook#24139 Doc about loading order https://developer.apple.com/documentation/objectivec/nsobject/1418815-load?language=objc [iOS] [Fixed] - Fix runtime crash in xcode 10.2 when using RCT_EXTERN_MODULE for swift classes. Pull Request resolved: facebook#24155 Reviewed By: javache Differential Revision: D14668235 Pulled By: shergin fbshipit-source-id: 0c19e69ce2a68327387809773848d4ecd36d7461
- Loading branch information