Giter VIP home page Giter VIP logo

Comments (23)

johnno1962 avatar johnno1962 commented on May 10, 2024

Where is MyProtocol defined? Is it in its own file or is it being injected as well? Or, you could also try setting the environment variable INJECTION_DYNAMIC_CAST in your scheme.

from inject.

romaHerman avatar romaHerman commented on May 10, 2024

It's In it's own file
Will try with env var now and let you know
P.S. Thanks for such fast reply!

from inject.

romaHerman avatar romaHerman commented on May 10, 2024

unfortunately it didn't help

from inject.

johnno1962 avatar johnno1962 commented on May 10, 2024

Any chance of a small example project so I could look into what's going on?

from inject.

romaHerman avatar romaHerman commented on May 10, 2024

Yes
Let me try to construct one

from inject.

romaHerman avatar romaHerman commented on May 10, 2024

Here is a sample project
https://github.com/romaHerman/InjectTest
It has TestComponents xCodeProject and main xCodeProject
in SceneDelegate you can find test invocations of methods

it's similar to my setup in main project

from inject.

johnno1962 avatar johnno1962 commented on May 10, 2024

Thanks for the example project. Injection aside, I can see that Inject.ViewControllerHost(CalendarViewController()) has type Inject._ViewControllerHost<CalendarViewController> not CalendarViewController which even though it is defined as a subclass of CalendarViewController does not acquire the conformance to TestProtocol. This seems to be a Swift thing. @krzysztofzablocki?

from inject.

johnno1962 avatar johnno1962 commented on May 10, 2024

... Perhaps you need to do something like:

        if let vc = vc.instance as? TestProtocol {
            vc.testPrint()
        }

from inject.

romaHerman avatar romaHerman commented on May 10, 2024

Thanks!

It does work in this case with vc.TestPrint()

but unfortunately it won't solve problem with passing this view to side menu

I have SideMenu which does navigationController.pushViewcontroller(<VC>)
and in order Inject to work in should push vc not vc.instance

problem is here

let calendar = Inject.ViewControllerHost(CalendarViewController())
sideMenu.view = calendar.instance

from inject.

johnno1962 avatar johnno1962 commented on May 10, 2024

How do you mean "for inject to work"? If you save the file containing CalendarViewController, its methods will have been overridden for the next time they are called again.

from inject.

romaHerman avatar romaHerman commented on May 10, 2024

here is what I'm trying to do

let calendar = Inject.ViewControllerHost(CalendarViewController())

viewControllers = [NewsViewController(), calendar.instance]
menu.viewcontrollers = viewControllers

inside menu viewControllers variable is declared like this
var viewControllers: [MenuProtocol] = []
and when I do
menu.selectedIndex = 1
inside it does following
navigationController.setViewcontrollers[viewControllers[selectedIndex]
so it sets calendar.instance not the calendar itself and I think this the problem why Inject doesn't hot reload it for me

from inject.

johnno1962 avatar johnno1962 commented on May 10, 2024

It's possible the "Hosting" model Inject uses may not be for you in this instance. When you save the file containing NewsViewController it will have been "swizzled" correctly. Perhaps you just need a way to force it to redraw. Have you looked at creating an `@objc func injected()' method which should be called when the class is injected inside which you call viewDidLoad() or configure() or something to force the redraw so you can see the hot reload.

from inject.

romaHerman avatar romaHerman commented on May 10, 2024

Thanks

I've overlooked this
How I can do that ?

from inject.

johnno1962 avatar johnno1962 commented on May 10, 2024

create an @objc func injected() function in your class and see if it gets called. If it does, then you can do some stuff in it.

from inject.

romaHerman avatar romaHerman commented on May 10, 2024

Maybe I will have to change SideMenu somehow to accept viewControllers
injected doesn't get called

from inject.

johnno1962 avatar johnno1962 commented on May 10, 2024

I can zoom if you get stuck.

from inject.

romaHerman avatar romaHerman commented on May 10, 2024

wow, thanks a lot!
if it works for you I'm ready
Tell me when you have time for that

from inject.

johnno1962 avatar johnno1962 commented on May 10, 2024

Or TeamView. Send an invite/login to github at johnholdsworth.com

from inject.

johnno1962 avatar johnno1962 commented on May 10, 2024

Actually, TeamView if you can thanks.

from inject.

romaHerman avatar romaHerman commented on May 10, 2024

well
I've changed my setup and now I don't need to solve this problem but somehow InjectionIII just quit working

I can see
InjectionIII connected /Users//Documents/App.xcworkspace
💉 Watching files under /Users//Documents/App.xcworkspace
and when I open debug view hierarchy in Xcode I can sett that there is InjectionHostVC
also I gave access to all files and folders in mac's security

But when I change view and save nothing happens

I've tried reinstalling app and installing again, installing from Mac App Store and also restarting Mac

from inject.

johnno1962 avatar johnno1962 commented on May 10, 2024

You seem to be watching the workspace file instead of watching the directory containing the workspace file. Use menu item "Open Project" to set it again.

from inject.

romaHerman avatar romaHerman commented on May 10, 2024

Ohhh
I somehow thought that I should select workspace

It's working now
Thanks a lot!!!

BTW here is how I hacked thing that I can't add this view to menu directly because of protocol
added this line in viewWillAppear so view controller will re-instantiate itself and thus re-add itself with Injected host
I will have to remove this code once I'm done working with this VC but it solves the issue

if injectSelf {
            let eventVC = Inject.ViewControllerHost(EventsViewController())
            eventVC.injectSelf = false
            navigationController?.setViewControllers([eventVC], animated: false)
        }

from inject.

krzysztofzablocki avatar krzysztofzablocki commented on May 10, 2024

for passing specific type only .instance can work, but in that scenario I'd recommend probably not commiting host changes, I usually just do host swap in separate commit I can easily delete at the end of feature work

from inject.

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.