Comments (6)
Hello. Thank you for pointing out the issue.
The current version of SwinjectStoryboard
does not have a way to pass arguments when you instantiate a view controller. I'll try to add the feature as an update later.
For now, one of workarounds is something like this:
// Somewhere you can access both from inside setup() and view controller instantiation.
var foo = ""
// Inside setup()
c.register(ViewModel.self) { _ in ViewModel(foo: foo) }
c.registerForStoryboard(ViewController.self) { r, vc in vc.vm = r.resolve(ViewModel.self) }
// Instantiate ViewController
foo = "foo"
sb.instantiateViewControllerWithIdentifier("ViewController")
, or register FooGetter
to the container:
c.register(FooGetter.self) { _ in FooGetter() }
c.register(ViewModel.self) { r in ViewModel(foo: r.resolve(FooGetter.self)) }
from swinject.
It would be nice to add a method like instantiateViewControllerWithIdentifier(_: arguments:)
to SwinjectStoryboard
.
@danishin, keep this issue open please? I'll take time to think how I can add the feature.
from swinject.
Thanks for your response. Yes, that'd be nice to have. I'll keep the issue open!
from swinject.
@yoichitgy Hello, has there been any update to this? This is the one last thing that I wanted to fix before going production 😢
from swinject.
I finished refactoring (6cb733d) to implement the storyboard feature, but I got other issues to do (#58, #59, #51).
Will you be able to try implementing the feature and sending a pull request❓Your help is really appreciated😃
from swinject.
@danishin, I was thinking how to implement the argument feature to SwinjectStoryboard
, but it was too complicated rather than my expectation because SwinjectStoryboard
has to inject dependencies not to the instantiating view controller but also its child view controller.
I'm not going to implement the feature, but I got a workaround for your case like this.
// Inside setup()
let c = Container()
c.register(ViewModel.self) { r, foo in ViewModel(foo: foo) }
c.registerForStoryboard(ViewController.self) { r, vc in vc.vm = r.resolve(ViewModel.self, arg1: ???) }
c.register(ViewController.self) { r, sb, a1 in
let vc = sb.instantiateViewControllerWithIdentifier("ViewController")
vc.vm = r.resolve(ViewModel.self, arg1: a1)
return vc
}
// Instantiate ViewController
let resolvedVC = c.resolve(ViewController.self, arguments: (sb, arg1))
Or you might be able to add a SwinjectStoryboard
to the container instead of passing it as an argument in resolve
method.
I couldn't find a straightforward solution for the arguments, but always welcome if you get a good idea to simply implement the feature.
from swinject.
Related Issues (20)
- Class with multiple initializers defined with Container scope, creates multiple objects HOT 1
- How to remove (unregister) a dependency with Swinject?
- Provider.instance throws a threading error
- Compiling with xCode 15 beta
- Build issue: Integration of SwiftLint into Xcode project not working on Apple Silicon Macs HOT 1
- Current deployment targets are not compatible with xCode 14.3 HOT 8
- Support for Async Await HOT 9
- Synchronous reads and writes fail
- What is the best way to distribute appDelegate events to all existing components?
- Privacy Manifest HOT 6
- Not building on visionOS HOT 1
- Latest version is not available on CocoaPods HOT 1
- Ownership Transfer of Swinject Project to Faire HOT 2
- Synchronized containers deadlock when reading from multiple threads
- Not able to install the latest version 2.8.4 via cocoapods HOT 3
- Privacy Manifest HOT 1
- Compilation issue with the latest version of 2.8.5 HOT 2
- Version 2.8.8 is broken in SPM HOT 6
- Resolver using swift generic varaidic argument? HOT 3
- visionOS : Invalid redeclaration of 'lock()' HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swinject.