johnno1962 / InjectionIII

Re-write of Injection for Xcode in (mostly) Swift
MIT License
3.98k stars 316 forks source link

Resource Copying #11

Closed garsdle closed 6 years ago

garsdle commented 6 years ago

First of all I love how useful injection is!

I was wondering if there is a way to extend this project to copy any modified file to the main bundle. I like the idea of reloading xibs and more.

I would be glad to try making the change myself with a pull request but wanted to check in and get pointed in the right direction. Maybe you have tried this and it is intractably hard.

Cheers! Manny

johnno1962 commented 6 years ago

This used to work sort-of in the old injection so you may be able to resurrect something. Storyboards are hard because the internal nib file names and connections get random names each time you recompile them making working out the right nib for a view controller difficult. Your starting point would be here: https://github.com/kzaher/injectionforxcode/commit/600275c19acf03c68277df3fa3af955ca68cdde5 with the last person who worked on this (only injecting xibs though)

garsdle commented 6 years ago

Awesome I'll take a look 👍

garsdle commented 6 years ago

When I run the project to debug and do start injection it stalls out at this line in HelperProxy without any error? mach_error_t err = [helper inject:[NSBundle mainBundle].bundlePath bundle:bundlePath client:__FILE__ dlopenPageOffset: dlopenPageOffset dlerrorPageOffset: dlerrorPageOffset];

johnno1962 commented 6 years ago

Did you update the code signing? If you get stuck on this you can add the following to your app and avoid this stage:

Bundle(path: "/Applications/InjectionIII.app/Contents/Resources/iOSInjection.bundle")?.load()

garsdle commented 6 years ago

Ok I've been digging in.

When trying to extract the compile command from .xcactivitylog for xibs it finds nothing

There is some serious magic going on at this level and I am not very gifted at perl nor regex so I have no idea why this is never true. elsif ($line =~ m@\(regexp.escaping("\"$"))@o and $line =~ " \(arch)") {

In my case regexp.escaping("\"$") evaluates to
-(?:primary-file|c(?<! -frontend -c)) (?:\\\\?\\\"(\\Q/Users/minombre/miprojecto/miprojecto/miprojecto/UI/ProductDetail/ProductDetailView.xib\\E)\\\\?\\\"|(\\Q/Users/minombre/miprojecto/miprojecto/miprojecto/UI/ProductDetail/ProductDetailView.xib\\E))

And I know that /Users/minombre/miprojecto/miprojecto/miprojecto/UI/ProductDetail/ProductDetailView.xib is in the .xcactivitylog

Any thoughts?

johnno1962 commented 6 years ago

That’s a regex for getting compile commands. The nib compiles will be different and not require the -(?:primary-file|c(?<! -frontend -c)) section which translates as -primary-fille or -c not followed by -frontend -c. There is a whole book on regex.

garsdle commented 6 years ago

Thanks. I'll give that a shot. I intend on not reading that book haha

garsdle commented 6 years ago

So I've decided to actually switch to just programming my UI and ditching IB all together. I'll mark this closed since programable UI works great with InjectionIII