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
DI with NIB/XIB #95
Comments
Hi @SantoDE. Thank you for using Swinject😃 This document might be helpful. I'll read your post and reply later. |
Thanks @yoichitgy . I looked that up already. However, looks like I'm too dumb ;) As I missed 1 code block, here we go:
|
Hi @SantoDE. I'm sorry but would you help me to investigate the issue? If you provide me the minimum code to reproduce the issue, it's much easier for me to investigate the possible bug of Swinject. Thanks😆 |
What would you need @yoichitgy ? :) I can provide what ever you need, because I'm stuck without ;) |
Reducing the number of properties and lines of code in your example is helpful. Thanks👍 |
Does this help @yoichitgy ?
|
Why do you expect |
Because I inject it in the SwinjectStoryBoard as a property? At least, that was my understanding. Maybe this is the error already ^.^ |
It's good practice to modify a working example of SwinjectStoryboard to get closer to the final thing you want to implement. Can you try a working example of SwinjectStoryboard first? Then modify it slightly closer to the RealmExample? You can continue the iteration to get the final result you want🚀 (Thanks for giving me to write this practice. I think some other people want to know this kind of things. Also I think I have to update the document of SwinjectStoryboard to provide easier way to understand😃) |
By the way, just the background of the minimum code to reproduce the issue was the same thing. No worries, I'm not upset😉 I'm just thinking how I can provide good documentation and example about SwinjectStoryboard. |
Maybe the problem is here?
It uses a NIB (XIB), not a storyboard. |
All fair :) I'll try to move from there then. For me, it looked like I'm missing something very obvious so you guys could see it rather fast. Maybe it just isn't ^.^ The realm part itself is working just fine, I'm just trying to combine both worlds by taking reference to the Weather App. Anyway, thanks and I'll try it again :) |
@yoichitgy then this will be the exact problem. Any documentation for that case? Please don't get me wrong, I'm eager to learn ^.^ |
Good to hear you got closer to the solution. We have no documentation for the case. I have to update the document to clearly state SwinjectStoryboard doesn't support NIB (XIB) but only Storyboard. |
Would it be possibble to Support nib? And what would be the go to way? Anyway, Thanks for your help :)
|
You can just use a simple Container to do DI with nib. Check below to learn DI with Swinject. |
This post looks good to learn DI with NIBs/XIBs. |
Thanks. I'm really struggling there. Will put some time to it during the next days. Currently, my closures are still not getting hit tough I try to register services inside my AppDelegate. It crashes because my DI Containers parent is nil. Not sure where I'm failing tough. |
Hey @yoichitgy . Sadly, I still can't resolve the issue of parent nil. Here's my appdelegate
It doesnt resolve SettingTypes Closure to add the service, as it gets an nil during working trough the closure. Any thing obvious wrong you can see with my delegate? EDIT It crashes here:
with the error
EDIT2 Looks like, my initial idea was wrong. Looks like, it crashes in register function of Container.swift as the serviceType appears to be nil. How is this possible, when I register the services to the container as shown above? Maybe you @yoichitgy have an idea :) |
Is there still no support for Swinject and Xibs? |
@Sajjon In what cases would you need special support for Xibs? Support for storyboard is required because you don't have view controller's initialisation under control, but when using Xibs they are constructed via initialiser which is perfect place to pass dependencies. However, I don't think this issue is the right place for future discussion, as it is bloated by a lot of stuff unrelated to the topic. Would you please create separate issue with description of the problem you are facing? Thanks 😉 |
@jakubvano how about the case when a view is loaded from the nib in the view controller by defining IBOutlet ? class MySubView: UIView { } |
Hey there,
I'm currently trying to get Swinject running. However, I'm struggling heavily to get the injection up and running. In my Setting.class, the property "dataSource" is always nil as it's not getting injected. What am I doing wrong? Looking for advice :)
Regards,
Manuel
The text was updated successfully, but these errors were encountered: