Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'@objc' class method in extension of subclass of 'SwinjectStoryboard' requires iOS 13.0.0 #173

Open
whendon opened this issue Jul 15, 2022 · 7 comments

Comments

@whendon
Copy link

whendon commented Jul 15, 2022

macOS Monterey 12.4 (21F79)

Xcode Version 13.2.1 (13C100)

inside my podfile Target:

  platform :ios, '10.0'
  pod 'Swinject', '~> 2.6.2'
  pod 'SwinjectStoryboard'

Do I have to target iOS 13 to use this version of Swinject?

@whendon
Copy link
Author

whendon commented Jul 15, 2022

Update: tried targeting ios 13 and it did not resolve the issue.

I also tried updating Swinject to 2.7.1, which did not resolve the issue. I tried Swinject 2.8.2, which did nothing.

I tried specifying SwinjectStoryboard 2.2.0, 2.2.1, and 2.2.2.

import SwinjectStoryboard
import Foundation

extension SwinjectStoryboard {
    @objc class func setup() { // THE ERROR IS ON THIS LINE
        
        defaultContainer.register(JsonClient.self) { _ in
            let mobileToken = preferences.string(forKey: "mobileAuthToken") ?? ""
            return JsonClient(mobileToken: mobileToken, baseUrl:BaseUrl )
        }
        
        defaultContainer.storyboardInitCompleted(SignInViewController.self) { r, c in
            c.client = r.resolve(JsonClient.self)!
        }
        ```

@davilinho
Copy link

davilinho commented Jul 20, 2022

I've same issue, anybody has a solution?

import SwinjectStoryboard

extension SwinjectStoryboard {
    @objc class func setup() { <--- IS NEVER CALLED SINCE iOS 13!!
...

@Sega-Zero
Copy link

for those who struggles with setup method in XCode 14, Either turn off dead strip option, or use this workaround:

__attribute__((constructor)) static void swinjectStoryboardSetupEntry(void);

@interface SwinjectStoryboard (SetUp)

@end

@implementation SwinjectStoryboard (SetUp)

// will never get called from outside, but allows to keep swinjectStoryboardSetupEntry away from stripping
- (void) avoidDeadStripping {
    swinjectStoryboardSetupEntry();
}

@end

__attribute__((constructor)) static void swinjectStoryboardSetupEntry(void) {
    if ([SwinjectStoryboard conformsToProtocol:@protocol(SwinjectStoryboardProtocol)] &&
        [SwinjectStoryboard respondsToSelector:@selector(setup)]) {
        [SwinjectStoryboard performSelector:@selector(setup)];
    }
}

@BarredEwe
Copy link
Contributor

BarredEwe commented Aug 26, 2022

Could you try this code? I think, it is important - using static func (not @objc func).

extension SwinjectStoryboard {
    static func setup() { // <- Static here, instead of @objc
        // ...
    }
}

If it works, i create PR for fixing docs.

@whendon
Copy link
Author

whendon commented Aug 26, 2022

I have already removed SwinjectStoryboard from my app - I will add it back in on Monday and attempt your change.

@sowoumar
Copy link

sowoumar commented Dec 2, 2022

Could you try this code? I think, it is important - using static func (not @objc func).

extension SwinjectStoryboard {
    static func setup() { // <- Static here, instead of @objc
        // ...
    }
}

If it works, i create PR for fixing docs.

I use Xcode 14, but I still have the same problem. Should I remove SwinjectStoryboard in my project?

@JHeisecke
Copy link

in my case is never entering the library SwinjectStoryboard, like it doesn't exists in my project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants