Swift class extensions and categories on Swift classes are not allowed to have +load methods
Asked Answered
F

6

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

Funch answered 30/3, 2019 at 21:49 Comment(9)
"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.Hippo
I don't have this method implemented in my project. (not load functions found)Funch
Hmmm... Interesting. Are you sure none of your dependancies have it?Hippo
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.Funch
@DanielBastidas did you find any solution? Getting this one as well, and can’t find the dependency which causes itJazminejazz
@Jazminejazz I just got the provisional solution bellow. If you found anything else, let me know. Cheers.Funch
Was SwinjectStoryboard Pod in my case. Try to find in the project "load(" and "(void)load" to find outFare
Now switching back also. This seems to be the issue: medium.com/post-mortem/…Jazminejazz
I had to download Simulator iOS 12.1 to get unblockedFaintheart
T
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.

Tycho answered 9/4, 2019 at 0:2 Comment(4)
We didn't have any RCT_EXPORT_MODULE problems, but upgrading to react-native version 0.59 also fixed this problem for us.Spoof
just replacing RCT_EXPORT_MODULE with RCT_EXPORT_MODULE_NO_LOAD cause some build errors...Westlund
Don't countless node_modules use this? Wouldn't they all need to be modified?Keely
@Keely 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.Tycho
F
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.

Funch answered 1/4, 2019 at 8:23 Comment(3)
Was SwinjectStoryboard Pod in my case if it can helpFare
version 2.2.0 should be fine now - the fix has been merged (github.com/Swinject/SwinjectStoryboard/releases/tag/2.2.0)Fare
just FYI, I had this problem with SwinjectAutoregistration Pod and there is also newer version available (github.com/Swinject/SwinjectAutoregistration/releases/tag/2.6.0)Congou
L
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!!!

Lynlyncean answered 1/4, 2019 at 22:2 Comment(0)
C
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

Cavity answered 3/6, 2019 at 11:54 Comment(0)
U
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.

Untouched answered 24/7, 2019 at 10:18 Comment(0)
C
-1

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

Chinch answered 24/4, 2019 at 10:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.