GithubHelp home page GithubHelp logo

Comments (16)

johnno1962 avatar johnno1962 commented on May 27, 2024

Hi, you seem to have a couple of issues mixed into one. Firstly, injection only updates function implementations but the new implementations are not re-called automatically. So, it cannot arrange for your ViewController to redraw and update the display on its own; You need to use one of the techniques described in the project README. That aside, inherited methods, particularly across modules is a tricky problem and you may have run across a limitation. Remember though, when injecting an inherited method remember to inject the superclass then inject the subclass again so it gets a change to update the subclass' vtable if you want to see it work.

from injectioniii.

chrisknapp98 avatar chrisknapp98 commented on May 27, 2024

My issue is completely unrelated to calling any methods, I know that. I just wanted to make clear how this specific architecture looks like.

I only expect a ViewControllers viewDidLoad() method to be re-executed because of the extension mentioned in the README

#if DEBUG
extension UIViewController {
    @objc func injected() {
        viewDidLoad()
    }
}
#endif

However, the viewDidLoad() is not executed when using those types from another module.

Unfortunately in my context adding a library to production code is not an option, so I am only able to load InjectionIII's bundle in AppDelegate, add the extension and the linker flags to the example project.

Have you got any further suggestion or am I maybe missing something?

from injectioniii.

johnno1962 avatar johnno1962 commented on May 27, 2024

Let's separate this into two problems. Are you saying the injected() method you add in your example project dependant on a pod containing the ViewControllers you're using isn't called? That would be unusual. Leave the sayHi() method to one side for a second.

from injectioniii.

chrisknapp98 avatar chrisknapp98 commented on May 27, 2024

yeah exactly. I updated the code to reduce confusion. There's no issue with calling any inherited methods whatsoever.

My only problem is that I need to go back and push the ViewController again to see the changes

from injectioniii.

johnno1962 avatar johnno1962 commented on May 27, 2024

I can see how that might happen though I need to think about it some more. The problem won't be with the @objc injected() method but the dispatch of the viewDidLoad() through the vtable(s). Recapping, which "the" ViewController do you need to push again to see the changes? If you see the changes, how does this not meet your expectations?

from injectioniii.

chrisknapp98 avatar chrisknapp98 commented on May 27, 2024

I need to push the TestViewController again (the one I am working on).
However, if at runtime I change TestViewController the following way, then my changes within viewDidLoad() update right-away.

class TestViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .systemGreen // changes are updated automatically in Simulator
    }
}

from injectioniii.

johnno1962 avatar johnno1962 commented on May 27, 2024

So if TestViewController inherits UIViewController directly it works but if it inherits MyViewControllerBase it doesn't?

from injectioniii.

chrisknapp98 avatar chrisknapp98 commented on May 27, 2024

exactly!

from injectioniii.

chrisknapp98 avatar chrisknapp98 commented on May 27, 2024

Unfortunately I cannot share the code with you. But maybe I find some time in the coming days to reproduce this in a sample project set up with cocoapods.
But I think now you're understanding my problem.

from injectioniii.

johnno1962 avatar johnno1962 commented on May 27, 2024

Very strange, I may take a look tomorrow if I can think of something fixable. It would be very helpful to me if you were able to prepare a small project demoing the problem.

from injectioniii.

chrisknapp98 avatar chrisknapp98 commented on May 27, 2024

Sure, but give me some days! You can also wait to not waste your time in case my problem lays somewhere else and I don't manage to reproduce it

from injectioniii.

johnno1962 avatar johnno1962 commented on May 27, 2024

Thanks! That would be very helpful; no hurry. By the way, I don't have Cocoapods installed on my machine but you should be able to replicate your problem by putting your superclasses in a framework target which is what Cocoapods does anyway.

from injectioniii.

johnno1962 avatar johnno1962 commented on May 27, 2024

Just a thought. Have you tried adding the injected() method to your TestViewController?

    @objc func injected() {
        viewDidLoad()
    }

from injectioniii.

johnno1962 avatar johnno1962 commented on May 27, 2024

Hi, I've tried a few things with a test project and not been able to replicate this problem. If you get a change to produce a small example app that shows the problem but doesn't use Cocoapods and post it here or email it to me via github at johnholdsworth.com I can take a look at it for you.

from injectioniii.

chrisknapp98 avatar chrisknapp98 commented on May 27, 2024

Just a thought. Have you tried adding the injected() method to your TestViewController?

    @objc func injected() {
        viewDidLoad()
    }

Yeah I tried that and it made no difference. It recognizes that I'd need to override it and when changing the extension from UIViewController to be on TestViewController instead, it still doesn't execute the viewDidLoad()

from injectioniii.

chrisknapp98 avatar chrisknapp98 commented on May 27, 2024

Hi, I've tried a few things with a test project and not been able to replicate this problem. If you get a change to produce a small example app that shows the problem but doesn't use Cocoapods and post it here or email it to me via github at johnholdsworth.com I can take a look at it for you.

Just spent some hours vaguely recreating the setup first with just two modules and that worked as you have stated already.
Then I tried to setup a comparable cocoapods environment and that also works fine. So the issue might be something different and I'll see if I casually find out what is causing it in the coming weeks.

So I guess we can close this issue for now and we'll see if I come back with a solution.

Thank you very much for your assistance!

from injectioniii.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.