23

I have updated Xcode Version 10.2 (10E125) and testing on devices (not only simulator)

I get this message when I execute the app:

objc[3297]: Swift class extensions and categories on Swift classes are not allowed to have +load methods

  • It's just not working on devices with iOS 12.2. I would like to know if there was any update that was affecting the swift classes. So far no answer about this in other forums just saw that apple has some issues with other apps in production as well.

-I'm using extensions of swift classes but I don't think that is the problem

  • Using Cocoapods and Firebase dependencies.

  • I searched in my project any functions that could contain "load" functions, none found.

Please some help

Daniel Bastidas
  • 1,795
  • 1
  • 9
  • 15
  • "Invoked whenever a class or category is added to the Objective-C runtime; implement this method to perform class-specific behavior upon loading." Swift classes are never added to the Objective C runtime, unless they're marked `@objc`. – Alexander Mar 30 '19 at 22:00
  • I don't have this method implemented in my project. (not load functions found) – Daniel Bastidas Mar 30 '19 at 22:15
  • Hmmm... Interesting. Are you sure none of your dependancies have it? – Alexander Mar 30 '19 at 22:18
  • I've been deleting dependencies, apparently no. Anyway, what it doesn't make sense is that is working on 12.1 iOS and not on 12.2 iOS. – Daniel Bastidas Mar 30 '19 at 22:23
  • @DanielBastidas did you find any solution? Getting this one as well, and can’t find the dependency which causes it – ofer2980 Mar 31 '19 at 12:15
  • @ofer2980 I just got the provisional solution bellow. If you found anything else, let me know. Cheers. – Daniel Bastidas Apr 01 '19 at 11:08
  • 1
    Was SwinjectStoryboard Pod in my case. Try to find in the project "load(" and "(void)load" to find out – rbiard Apr 01 '19 at 13:46
  • Now switching back also. This seems to be the issue: https://medium.com/post-mortem/using-nsobjects-load-and-initialize-from-swift-f6f2c6d9aad0 – ofer2980 Apr 01 '19 at 15:56
  • I had to download Simulator iOS 12.1 to get unblocked – a.ajwani Apr 14 '19 at 19:41

6 Answers6

7

Just to add a solution for React Native projects.

This issue occurred because one of our custom react native modules was using the RCT_EXPORT_MODULE() macro which calls the init function and we were also including swift code. Since react-native version 0.59.3, there's a new macro RCT_EXPORT_MODULE_NO_LOAD(js_name, objc_name) which avoids the call to init. Replacing RCT_EXPORT_MODULE() with RCT_EXPORT_MODULE_NO_LOAD(js_name, objc_name) and updating to react native version 0.59.3 fixed the issue.

Ethan Worley
  • 685
  • 7
  • 13
  • 2
    We didn't have any RCT_EXPORT_MODULE problems, but upgrading to react-native version 0.59 also fixed this problem for us. – gregkerzhner Apr 16 '19 at 22:51
  • just replacing RCT_EXPORT_MODULE with RCT_EXPORT_MODULE_NO_LOAD cause some build errors... – Asatur Galstyan May 10 '19 at 18:56
  • Don't countless node_modules use this? Wouldn't they all need to be modified? – JeremyF Dec 20 '19 at 02:26
  • 1
    @JeremyF it's been a while since I wrote this answer, but I believe the issue was using `RCT_EXPORT_MODULE()` specifically with swift code, so only node modules in a similar situation would need to be updated. It seems like for most RN projects, updating the version was enough. – Ethan Worley Dec 23 '19 at 03:08
4

At the moment the quick fix:

Once you've done that, rebuild your project and it works just fine on any device.

I think the problem is related to Swift 5. What we would probably need to do is update all the dependencies to Swift 5. At the moment I don't have the time to do so.


The long fix: Is update your pods and slowly migrate toward swift5.

The pod that was giving more problems was: Swinject with SwinjectStoryboard, and RxOptional.

Daniel Bastidas
  • 1,795
  • 1
  • 9
  • 15
  • 10
    Was SwinjectStoryboard Pod in my case if it can help – rbiard Apr 01 '19 at 13:49
  • 3
    version 2.2.0 should be fine now - the fix has been merged (https://github.com/Swinject/SwinjectStoryboard/releases/tag/2.2.0) – rbiard Apr 01 '19 at 22:53
  • just FYI, I had this problem with SwinjectAutoregistration Pod and there is also newer version available (https://github.com/Swinject/SwinjectAutoregistration/releases/tag/2.6.0) – Przemyslaw Jablonski Apr 14 '19 at 22:53
4

In my case the only one dependency that has +load method is RxAtomic. Which, by the way, is the only one that didn't update to the current moment to swift 5.0. So I suppose this bug caused by RxSwift. And I also have Swinjects dependencies, but updated all to the newest releases that support swift 5 - it didn't help.

EDIT

I just open Pods project file. Select RxAtomic Target. And change User-Defined property 'SWIFT_VERSION' from 5.0 to 4.2. And it works!!!

Nikita Haiko
  • 371
  • 3
  • 6
3

upgrade to react-native version ^0.59.5

solved it without RCT_EXPORT_MODULE_NO_LOAD,

to update react-native version,

rm -rf node_modules
yarn add react-native@^0.59.5

so this will update other dependancies packages with the new version

Mustafa
  • 61
  • 5
0

I had the same problem and all I did was to update pods. Swinject pod was causing problem and after update to the latest version everything was solved. You may also try to adjust Swift language version in Pods Targets.

Mile Dev
  • 652
  • 6
  • 13
-1

• Downgrading to Xcode 10.0 solved the issue in my case. You can download it at More Downloads for Apple Developers