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

Injection does not work with Generic Classes #244

Open
mkkroliks opened this issue Apr 24, 2018 · 2 comments
Open

Injection does not work with Generic Classes #244

mkkroliks opened this issue Apr 24, 2018 · 2 comments

Comments

@mkkroliks
Copy link

mkkroliks commented Apr 24, 2018

Hey I just realized that injection doesn't work when I subclass view controller from generic view controller. I have a file like this.

import UIKit

class GenericController<A>: BaseViewController {
    
}

class NonGenericController: BaseViewController {
    
}

class LoginViewController: GenericController<UIView> {

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .white
    }
    
    #if DEBUG
    @objc func injected() {
        for subview in self.view.subviews {
            subview.removeFromSuperview()
        }
        viewDidLoad()
    }
    #endif
}

When I subclass like this it's doesn't reload and I'm getting following output:

`Compiling /Users/mk/proexe/dogWalkTrophy-ios/DogWalkTrophy/DogWalkTrophy/Screens/Login/LoginViewController.swift

Injection: Loading /Users/mk/Library/Developer/Xcode/DerivedData/DogWalkTrophy-ckqnnpzyqukneiczeuwblphvsqyg/Logs/iOSInjectionProject/build/Debug-iphonesimulator/InjectionBundle100.bundle
objc[35393]: Class _TtC13DogWalkTrophy20NonGenericController is implemented in both /Users/mk/Library/Developer/CoreSimulator/Devices/78BAC6B7-531C-4136-9581-65147C03C856/data/Containers/Bundle/Application/FE4C6AD6-4AF6-4270-88F7-08D182370AE7/DogWalkTrophy.app/DogWalkTrophy (0x10f994810) and /Users/mk/Library/Developer/Xcode/DerivedData/DogWalkTrophy-ckqnnpzyqukneiczeuwblphvsqyg/Logs/iOSInjectionProject/build/Debug-iphonesimulator/InjectionBundle100.bundle/InjectionBundle (0x13269e7a0). One of the two will be used. Which one is undefined.
80 injections performed so far.
Injection: Ignore any warning, Swizzled DogWalkTrophy.NonGenericController 0x13269e7a0 -> 0x10f994810`

but when subclass from non generic code everything works fine:

class LoginViewController: NonGenericController {

Why is that? Anyone has some idea? Thanks!

@johnno1962
Copy link
Owner

johnno1962 commented Apr 24, 2018

Generic classes are not visible to the Objective-C runtime which injection uses so this is not possible. You could argue a concrete non-generic subclass should be represented somehow but that’s more of a Swift bug.

@mkkroliks
Copy link
Author

@johnno1962 thanks for answer, that makes sense!

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

2 participants