johnno1962 / InjectionIII

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

Issue injection xib files #43

Closed zenangst closed 5 years ago

zenangst commented 5 years ago

Hey John,

I've been tinkering a bit with injecting xib-files (tinkering is a bit of an overstatement) but I'm stuck when trying to save the xib-file. An exception is thrown with the following error description:

Problem reloading nib: *** -[__NSDictionaryM setObject:forKeyedSubscript:]: key cannot be nil

Anything in particular that I need to configure or set in my xib-file in order to get this working? The project is an iOS project if that helps narrow it down, so far I've tracked it back to https://github.com/johnno1962/InjectionIII/blob/MAS-version/InjectionBundle/InjectionClient.mm#L212

Unsure what is causing it to throw, any ideas?

johnno1962 commented 5 years ago

Hi Chris,

I’m sure your guess is as good as mine on this. In truth the nib/storyboard injection works only to a point and the problem is probably trying to reconstruct connections the problem being that they have random identifiers that change each time the file is saved. The code tries to account for this by creating a map of the names according to the order they are referred to when the file is first injected. Sorry I can’t be much more help!

John

zenangst commented 5 years ago

I debugged it a bit more and was able to solve the initial problem when loading the nib file. So the view controller was written in code and thus didn't have a nibName set. I also had to rename the target to not use any spaces (I think I've seen similar issues about paths before, escaping strings is not a trivial task). However, it seems as if the nib injecting is a bit unreliable, just as you said. Couldn't get it to work properly when testing. Injecting in code works just fine but the views don't seem to react when new instances of the xib are injected. I bet this is the random identifiers causing shenanigans just as you mentioned.

I'll look into this a bit further just out of curiosity, for me, this is basically a non-issue as I don't use xib or storyboards when developing.

johnno1962 commented 5 years ago

Injecting nibs was a bit of a nice to have for iterating or UIs. It definitely doesn’t mix well with injection!

zenangst commented 5 years ago

I believe that this PR should fix this issue: https://github.com/johnno1962/InjectionIII/pull/76

zenangst commented 5 years ago

This particular issue should be fixed by now. There might be more improvements to injecting storyboards or xibs but they should be handled as separate issues.