From 1833160daf21abb580cb9eea6f84dd35f40c73e6 Mon Sep 17 00:00:00 2001 From: Malkevych Bohdan Date: Thu, 10 Aug 2017 20:41:40 +0300 Subject: [PATCH 01/21] implemented ability to add arguments to inject them to UIViewControllers --- Sources/SwinjectStoryboardExtensions.swift | 85 ++++++++++++++++++++ SwinjectStoryboard.xcodeproj/project.pbxproj | 8 ++ 2 files changed, 93 insertions(+) create mode 100644 Sources/SwinjectStoryboardExtensions.swift diff --git a/Sources/SwinjectStoryboardExtensions.swift b/Sources/SwinjectStoryboardExtensions.swift new file mode 100644 index 0000000..1d66365 --- /dev/null +++ b/Sources/SwinjectStoryboardExtensions.swift @@ -0,0 +1,85 @@ +// +// SwinjectStoryboardExtensions.swift +// SwinjectStoryboard +// +// Created by Malkevych Bohdan on 10.08.17. +// Copyright © 2017 Swinject Contributors. All rights reserved. +// + +import Swinject + +#if os(iOS) || os(OSX) || os(tvOS) + extension Container { + /// Adds a registration of the specified view or window controller that is configured in a storyboard. + /// + /// - Note: Do NOT explicitly resolve the controller registered by this method. + /// The controller is intended to be resolved by `SwinjectStoryboard` implicitly. + /// + /// - Parameters: + /// - controllerType: The controller type to register as a service type. + /// The type is `UIViewController` in iOS, `NSViewController` or `NSWindowController` in OS X. + /// - name: A registration name, which is used to differenciate from other registrations + /// that have the same view or window controller type. + /// - initCompleted: A closure to specifiy how the dependencies of the view or window controller are injected. + /// It is invoked by the `Container` when the view or window controller is instantiated by `SwinjectStoryboard`. + + public func storyboardInitCompletedArg(_ controllerType: C.Type, + name: String? = nil, initCompleted: @escaping (Resolver, C, Arg) -> ()) { + var arg: Arg! + let factory = { (_: Resolver, controller: Controller, + argLocal: Arg) -> Container.Controller in + arg = argLocal + return controller + } + + let option = SwinjectStoryboardOption(controllerType: controllerType) + + let wrappingClosure: (Resolver, Controller) -> () = { r, c in + initCompleted(r, c as! C, arg) + } + _register(Controller.self, factory: factory, name: name, option: option) + .initCompleted(wrappingClosure) + } + } +#endif + +extension SwinjectStoryboard { + + #if os(iOS) || os(tvOS) + + private func injectDependency(to viewController: UIViewController, arg: Arg) { + guard !viewController.wasInjected else { return } + defer { viewController.wasInjected = true } + + let registrationName = viewController.swinjectRegistrationName + + // Xcode 7.1 workaround for Issue #10. This workaround is not necessary with Xcode 7. + // If a future update of Xcode fixes the problem, replace the resolution with the following code and fix storyboardInitCompleted too. + // https://github.com/Swinject/Swinject/issues/10 + if let container = container.value as? _Resolver { + let option = SwinjectStoryboardOption(controllerType: type(of: viewController)) + typealias FactoryType = (Resolver, Container.Controller, Arg) -> Container.Controller + let _ = container._resolve(name: registrationName, option: option) { (factory: FactoryType) in factory(self.container.value, viewController, arg) } + } else { + fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") + } + + for child in viewController.childViewControllers { + injectDependency(to: child) + } + } + + public func instantiateViewController(withIdentifier identifier: String, + arg: Arg) -> UIViewController { + SwinjectStoryboard.pushInstantiatingStoryboard(self) + let viewController = super.instantiateViewController(withIdentifier: identifier) + SwinjectStoryboard.popInstantiatingStoryboard() + + injectDependency(to: viewController, arg: arg) + + return viewController + } + + #endif + +} diff --git a/SwinjectStoryboard.xcodeproj/project.pbxproj b/SwinjectStoryboard.xcodeproj/project.pbxproj index 08217fc..3679310 100644 --- a/SwinjectStoryboard.xcodeproj/project.pbxproj +++ b/SwinjectStoryboard.xcodeproj/project.pbxproj @@ -81,6 +81,9 @@ 98978E6A1DFC354B0046B966 /* UnavailableItems.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98978E671DFC354B0046B966 /* UnavailableItems.swift */; }; 98D562821CDB173500DECDC0 /* SwinjectStoryboard.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 98D562781CDB173500DECDC0 /* SwinjectStoryboard.framework */; }; 98D5629E1CDB19AB00DECDC0 /* SwinjectStoryboard.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 98D562941CDB19AB00DECDC0 /* SwinjectStoryboard.framework */; }; + B92E951F1F3CCEAD0051FD3E /* SwinjectStoryboardExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92E951E1F3CCEAD0051FD3E /* SwinjectStoryboardExtensions.swift */; }; + B92E95201F3CCEAD0051FD3E /* SwinjectStoryboardExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92E951E1F3CCEAD0051FD3E /* SwinjectStoryboardExtensions.swift */; }; + B92E95211F3CCEAD0051FD3E /* SwinjectStoryboardExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92E951E1F3CCEAD0051FD3E /* SwinjectStoryboardExtensions.swift */; }; CD2C63AA1D7864840075BC14 /* SwinjectStoryboard+StoryboardReference.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD2C63A91D7864840075BC14 /* SwinjectStoryboard+StoryboardReference.swift */; }; CD2C63AB1D7864840075BC14 /* SwinjectStoryboard+StoryboardReference.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD2C63A91D7864840075BC14 /* SwinjectStoryboard+StoryboardReference.swift */; }; CD2C63AD1D786C1F0075BC14 /* RelationshipReference1.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CD2C63AC1D786C1F0075BC14 /* RelationshipReference1.storyboard */; }; @@ -254,6 +257,7 @@ 98D562CA1CDB1E8800DECDC0 /* tvOS-Base.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = "tvOS-Base.xcconfig"; sourceTree = ""; }; 98D562CB1CDB1E8800DECDC0 /* tvOS-Framework.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = "tvOS-Framework.xcconfig"; sourceTree = ""; }; 98D562CC1CDB1E8800DECDC0 /* tvOS-StaticLibrary.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = "tvOS-StaticLibrary.xcconfig"; sourceTree = ""; }; + B92E951E1F3CCEAD0051FD3E /* SwinjectStoryboardExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwinjectStoryboardExtensions.swift; sourceTree = ""; }; CD2C63A91D7864840075BC14 /* SwinjectStoryboard+StoryboardReference.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "SwinjectStoryboard+StoryboardReference.swift"; sourceTree = ""; }; CD2C63AC1D786C1F0075BC14 /* RelationshipReference1.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = RelationshipReference1.storyboard; sourceTree = ""; }; CD2C63AE1D786CD70075BC14 /* RelationshipReference2.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = RelationshipReference2.storyboard; sourceTree = ""; }; @@ -456,6 +460,7 @@ 98978E671DFC354B0046B966 /* UnavailableItems.swift */, 985904091CDB0AA700275E4A /* SwinjectStoryboard.h */, 9859040B1CDB0AA700275E4A /* Info.plist */, + B92E951E1F3CCEAD0051FD3E /* SwinjectStoryboardExtensions.swift */, ); path = Sources; sourceTree = ""; @@ -906,6 +911,7 @@ 983DFF0B1CDB440800D39731 /* Box.swift in Sources */, 983DFEBE1CDB414900D39731 /* _SwinjectStoryboardBase.m in Sources */, 983DFEB41CDB410D00D39731 /* ViewController+Swinject.swift in Sources */, + B92E951F1F3CCEAD0051FD3E /* SwinjectStoryboardExtensions.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -943,6 +949,7 @@ 983DFF0C1CDB440800D39731 /* Box.swift in Sources */, 983DFEC41CDB415300D39731 /* _SwinjectStoryboardBase.m in Sources */, 983DFEB51CDB410D00D39731 /* ViewController+Swinject.swift in Sources */, + B92E95201F3CCEAD0051FD3E /* SwinjectStoryboardExtensions.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -981,6 +988,7 @@ 983DFF0D1CDB440800D39731 /* Box.swift in Sources */, 983DFEBF1CDB414900D39731 /* _SwinjectStoryboardBase.m in Sources */, 983DFEB61CDB410D00D39731 /* ViewController+Swinject.swift in Sources */, + B92E95211F3CCEAD0051FD3E /* SwinjectStoryboardExtensions.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; From 20085623afa367956d0153b5e8e871f224f6eaf9 Mon Sep 17 00:00:00 2001 From: Malkevych Bohdan Date: Thu, 10 Aug 2017 20:45:06 +0300 Subject: [PATCH 02/21] updated pod spec --- SwinjectStoryboard.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SwinjectStoryboard.podspec b/SwinjectStoryboard.podspec index 8bff22e..14d19d0 100644 --- a/SwinjectStoryboard.podspec +++ b/SwinjectStoryboard.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.homepage = "https://github.com/Swinject/SwinjectStoryboard" s.license = 'MIT' s.author = 'Swinject Contributors' - s.source = { :git => "https://github.com/Swinject/SwinjectStoryboard.git", :tag => s.version.to_s } + s.source = { :git => "https://github.com/SeductiveMobile/SwinjectStoryboard.git", :tag => s.version.to_s } core_files = 'Sources/*.swift' umbrella_header_file = 'Sources/SwinjectStoryboard.h' # Must be at the end of 'source_files' to workaround CococaPods issue. From e182cbe875b40355892ed45013edbacf9faba190 Mon Sep 17 00:00:00 2001 From: Malkevych Bohdan Date: Thu, 10 Aug 2017 20:51:47 +0300 Subject: [PATCH 03/21] fixed acces control --- Sources/SwinjectStoryboard.swift | 44 +++++++++++++++++++++- Sources/SwinjectStoryboardExtensions.swift | 41 -------------------- 2 files changed, 43 insertions(+), 42 deletions(-) diff --git a/Sources/SwinjectStoryboard.swift b/Sources/SwinjectStoryboard.swift index 7d6e83d..d5bc225 100644 --- a/Sources/SwinjectStoryboard.swift +++ b/Sources/SwinjectStoryboard.swift @@ -87,7 +87,7 @@ public class SwinjectStoryboard: _SwinjectStoryboardBase, SwinjectStoryboardProt return viewController } - private func injectDependency(to viewController: UIViewController) { + fileprivate func injectDependency(to viewController: UIViewController) { guard !viewController.wasInjected else { return } defer { viewController.wasInjected = true } @@ -158,3 +158,45 @@ public class SwinjectStoryboard: _SwinjectStoryboardBase, SwinjectStoryboardProt } #endif + + +extension SwinjectStoryboard { + + #if os(iOS) || os(tvOS) + + private func injectDependency(to viewController: UIViewController, arg: Arg) { + guard !viewController.wasInjected else { return } + defer { viewController.wasInjected = true } + + let registrationName = viewController.swinjectRegistrationName + + // Xcode 7.1 workaround for Issue #10. This workaround is not necessary with Xcode 7. + // If a future update of Xcode fixes the problem, replace the resolution with the following code and fix storyboardInitCompleted too. + // https://github.com/Swinject/Swinject/issues/10 + if let container = container.value as? _Resolver { + let option = SwinjectStoryboardOption(controllerType: type(of: viewController)) + typealias FactoryType = (Resolver, Container.Controller, Arg) -> Container.Controller + let _ = container._resolve(name: registrationName, option: option) { (factory: FactoryType) in factory(self.container.value, viewController, arg) } + } else { + fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") + } + + for child in viewController.childViewControllers { + injectDependency(to: child) + } + } + + public func instantiateViewController(withIdentifier identifier: String, + arg: Arg) -> UIViewController { + SwinjectStoryboard.pushInstantiatingStoryboard(self) + let viewController = super.instantiateViewController(withIdentifier: identifier) + SwinjectStoryboard.popInstantiatingStoryboard() + + injectDependency(to: viewController, arg: arg) + + return viewController + } + + #endif + +} diff --git a/Sources/SwinjectStoryboardExtensions.swift b/Sources/SwinjectStoryboardExtensions.swift index 1d66365..2f0c60b 100644 --- a/Sources/SwinjectStoryboardExtensions.swift +++ b/Sources/SwinjectStoryboardExtensions.swift @@ -42,44 +42,3 @@ import Swinject } } #endif - -extension SwinjectStoryboard { - - #if os(iOS) || os(tvOS) - - private func injectDependency(to viewController: UIViewController, arg: Arg) { - guard !viewController.wasInjected else { return } - defer { viewController.wasInjected = true } - - let registrationName = viewController.swinjectRegistrationName - - // Xcode 7.1 workaround for Issue #10. This workaround is not necessary with Xcode 7. - // If a future update of Xcode fixes the problem, replace the resolution with the following code and fix storyboardInitCompleted too. - // https://github.com/Swinject/Swinject/issues/10 - if let container = container.value as? _Resolver { - let option = SwinjectStoryboardOption(controllerType: type(of: viewController)) - typealias FactoryType = (Resolver, Container.Controller, Arg) -> Container.Controller - let _ = container._resolve(name: registrationName, option: option) { (factory: FactoryType) in factory(self.container.value, viewController, arg) } - } else { - fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") - } - - for child in viewController.childViewControllers { - injectDependency(to: child) - } - } - - public func instantiateViewController(withIdentifier identifier: String, - arg: Arg) -> UIViewController { - SwinjectStoryboard.pushInstantiatingStoryboard(self) - let viewController = super.instantiateViewController(withIdentifier: identifier) - SwinjectStoryboard.popInstantiatingStoryboard() - - injectDependency(to: viewController, arg: arg) - - return viewController - } - - #endif - -} From 6c8dddda8d5fa2190ae86b4daebaec3cb583bed4 Mon Sep 17 00:00:00 2001 From: Malkevych Bohdan Date: Fri, 11 Aug 2017 14:10:00 +0300 Subject: [PATCH 04/21] added 3 arguments to SwinjectStoryboard --- Sources/SwinjectStoryboard.swift | 71 ++++++++++++++++++++++ Sources/SwinjectStoryboardExtensions.swift | 45 +++++++++++++- 2 files changed, 114 insertions(+), 2 deletions(-) diff --git a/Sources/SwinjectStoryboard.swift b/Sources/SwinjectStoryboard.swift index d5bc225..0ffb4e7 100644 --- a/Sources/SwinjectStoryboard.swift +++ b/Sources/SwinjectStoryboard.swift @@ -186,6 +186,53 @@ extension SwinjectStoryboard { } } + private func injectDependency(to viewController: UIViewController, arg1: Arg1, arg2: Arg2) { + guard !viewController.wasInjected else { return } + defer { viewController.wasInjected = true } + + let registrationName = viewController.swinjectRegistrationName + + // Xcode 7.1 workaround for Issue #10. This workaround is not necessary with Xcode 7. + // If a future update of Xcode fixes the problem, replace the resolution with the following code and fix storyboardInitCompleted too. + // https://github.com/Swinject/Swinject/issues/10 + if let container = container.value as? _Resolver { + let option = SwinjectStoryboardOption(controllerType: type(of: viewController)) + typealias FactoryType = (Resolver, Container.Controller, Arg) -> Container.Controller + let _ = container._resolve(name: registrationName, option: option) { (factory: FactoryType) in factory(self.container.value, viewController, arg1, arg2) } + } else { + fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") + } + + for child in viewController.childViewControllers { + injectDependency(to: child) + } + } + + private func injectDependency(to viewController: UIViewController, + arg1: Arg1, arg2: Arg2, arg3: Arg3) { + guard !viewController.wasInjected else { return } + defer { viewController.wasInjected = true } + + let registrationName = viewController.swinjectRegistrationName + + // Xcode 7.1 workaround for Issue #10. This workaround is not necessary with Xcode 7. + // If a future update of Xcode fixes the problem, replace the resolution with the following code and fix storyboardInitCompleted too. + // https://github.com/Swinject/Swinject/issues/10 + if let container = container.value as? _Resolver { + let option = SwinjectStoryboardOption(controllerType: type(of: viewController)) + typealias FactoryType = (Resolver, Container.Controller, Arg) -> Container.Controller + let _ = container._resolve(name: registrationName, option: option) { (factory: FactoryType) in factory(self.container.value, viewController, arg1, arg2, arg3) } + } else { + fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") + } + + for child in viewController.childViewControllers { + injectDependency(to: child) + } + } + + //MARK: - instantiateViewController with Args + public func instantiateViewController(withIdentifier identifier: String, arg: Arg) -> UIViewController { SwinjectStoryboard.pushInstantiatingStoryboard(self) @@ -197,6 +244,30 @@ extension SwinjectStoryboard { return viewController } + public func instantiateViewController(withIdentifier identifier: String, + arg1: Arg1, arg2: Arg2) -> UIViewController { + SwinjectStoryboard.pushInstantiatingStoryboard(self) + let viewController = super.instantiateViewController(withIdentifier: identifier) + SwinjectStoryboard.popInstantiatingStoryboard() + + injectDependency(to: viewController, arg1: arg1, arg2: arg2) + + return viewController + } + + public func instantiateViewController(withIdentifier identifier: String, + arg1: Arg1, arg2: Arg2, arg3: Arg3) -> UIViewController { + SwinjectStoryboard.pushInstantiatingStoryboard(self) + let viewController = super.instantiateViewController(withIdentifier: identifier) + SwinjectStoryboard.popInstantiatingStoryboard() + + injectDependency(to: viewController, arg1: arg1, arg2: arg2, arg3: arg3) + + return viewController + } + + + #endif } diff --git a/Sources/SwinjectStoryboardExtensions.swift b/Sources/SwinjectStoryboardExtensions.swift index 2f0c60b..2317726 100644 --- a/Sources/SwinjectStoryboardExtensions.swift +++ b/Sources/SwinjectStoryboardExtensions.swift @@ -32,11 +32,52 @@ import Swinject return controller } - let option = SwinjectStoryboardOption(controllerType: controllerType) - let wrappingClosure: (Resolver, Controller) -> () = { r, c in initCompleted(r, c as! C, arg) } + register(factory: factory, name: name) + } + + public func storyboardInitCompletedArgs(_ controllerType: C.Type, + name: String? = nil, + initCompleted: @escaping (Resolver, C, Arg1, Arg2) -> ()) { + var arg1: Arg1! + var arg2: Arg2! + let factory = { (_: Resolver, controller: Controller, + argLocal1: Arg1, argLocal2: Arg2) -> Container.Controller in + arg1 = argLocal1 + arg2 = argLocal2 + return controller + } + + let wrappingClosure: (Resolver, Controller) -> () = { r, c in + initCompleted(r, c as! C, arg1, arg2) + } + register(factory: factory, name: name) + } + + public func storyboardInitCompletedArgs(_ controllerType: C.Type, + name: String? = nil, + initCompleted: @escaping (Resolver, C, Arg1, Arg2, Arg3) -> ()) { + var arg1: Arg1! + var arg2: Arg2! + var arg3: Arg3! + let factory = { (_: Resolver, controller: Controller, + argLocal1: Arg1, argLocal2: Arg2, argLocal3: Arg3) -> Container.Controller in + arg1 = argLocal1 + arg2 = argLocal2 + arg3 = argLocal3 + return controller + } + + let wrappingClosure: (Resolver, Controller) -> () = { r, c in + initCompleted(r, c as! C, arg1, arg2, arg3) + } + register(factory: factory, name: name) + } + + private func register(factory: FactoryType, name: String?) { + let option = SwinjectStoryboardOption(controllerType: controllerType) _register(Controller.self, factory: factory, name: name, option: option) .initCompleted(wrappingClosure) } From fa8cd96742b12d684dec003642bc5bf0485ec243 Mon Sep 17 00:00:00 2001 From: Malkevych Bohdan Date: Fri, 11 Aug 2017 14:29:35 +0300 Subject: [PATCH 05/21] fixed bugs connected to passing 3 arguments to VC --- Sources/SwinjectStoryboard.swift | 42 +++++++--------------- Sources/SwinjectStoryboardExtensions.swift | 13 +++---- 2 files changed, 20 insertions(+), 35 deletions(-) diff --git a/Sources/SwinjectStoryboard.swift b/Sources/SwinjectStoryboard.swift index 0ffb4e7..8c9409a 100644 --- a/Sources/SwinjectStoryboard.swift +++ b/Sources/SwinjectStoryboard.swift @@ -169,10 +169,7 @@ extension SwinjectStoryboard { defer { viewController.wasInjected = true } let registrationName = viewController.swinjectRegistrationName - - // Xcode 7.1 workaround for Issue #10. This workaround is not necessary with Xcode 7. - // If a future update of Xcode fixes the problem, replace the resolution with the following code and fix storyboardInitCompleted too. - // https://github.com/Swinject/Swinject/issues/10 + if let container = container.value as? _Resolver { let option = SwinjectStoryboardOption(controllerType: type(of: viewController)) typealias FactoryType = (Resolver, Container.Controller, Arg) -> Container.Controller @@ -191,13 +188,10 @@ extension SwinjectStoryboard { defer { viewController.wasInjected = true } let registrationName = viewController.swinjectRegistrationName - - // Xcode 7.1 workaround for Issue #10. This workaround is not necessary with Xcode 7. - // If a future update of Xcode fixes the problem, replace the resolution with the following code and fix storyboardInitCompleted too. - // https://github.com/Swinject/Swinject/issues/10 + if let container = container.value as? _Resolver { let option = SwinjectStoryboardOption(controllerType: type(of: viewController)) - typealias FactoryType = (Resolver, Container.Controller, Arg) -> Container.Controller + typealias FactoryType = (Resolver, Container.Controller, Arg1, Arg2) -> Container.Controller let _ = container._resolve(name: registrationName, option: option) { (factory: FactoryType) in factory(self.container.value, viewController, arg1, arg2) } } else { fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") @@ -214,13 +208,10 @@ extension SwinjectStoryboard { defer { viewController.wasInjected = true } let registrationName = viewController.swinjectRegistrationName - - // Xcode 7.1 workaround for Issue #10. This workaround is not necessary with Xcode 7. - // If a future update of Xcode fixes the problem, replace the resolution with the following code and fix storyboardInitCompleted too. - // https://github.com/Swinject/Swinject/issues/10 + if let container = container.value as? _Resolver { let option = SwinjectStoryboardOption(controllerType: type(of: viewController)) - typealias FactoryType = (Resolver, Container.Controller, Arg) -> Container.Controller + typealias FactoryType = (Resolver, Container.Controller, Arg1, Arg2, Arg3) -> Container.Controller let _ = container._resolve(name: registrationName, option: option) { (factory: FactoryType) in factory(self.container.value, viewController, arg1, arg2, arg3) } } else { fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") @@ -235,39 +226,32 @@ extension SwinjectStoryboard { public func instantiateViewController(withIdentifier identifier: String, arg: Arg) -> UIViewController { - SwinjectStoryboard.pushInstantiatingStoryboard(self) - let viewController = super.instantiateViewController(withIdentifier: identifier) - SwinjectStoryboard.popInstantiatingStoryboard() - + let viewController = loadViewController(with: identifier) injectDependency(to: viewController, arg: arg) - return viewController } public func instantiateViewController(withIdentifier identifier: String, arg1: Arg1, arg2: Arg2) -> UIViewController { - SwinjectStoryboard.pushInstantiatingStoryboard(self) - let viewController = super.instantiateViewController(withIdentifier: identifier) - SwinjectStoryboard.popInstantiatingStoryboard() - + let viewController = loadViewController(with: identifier) injectDependency(to: viewController, arg1: arg1, arg2: arg2) - return viewController } public func instantiateViewController(withIdentifier identifier: String, arg1: Arg1, arg2: Arg2, arg3: Arg3) -> UIViewController { + let viewController = loadViewController(with: identifier) + injectDependency(to: viewController, arg1: arg1, arg2: arg2, arg3: arg3) + return viewController + } + + private func loadViewController(with identifier: String) -> UIViewController { SwinjectStoryboard.pushInstantiatingStoryboard(self) let viewController = super.instantiateViewController(withIdentifier: identifier) SwinjectStoryboard.popInstantiatingStoryboard() - - injectDependency(to: viewController, arg1: arg1, arg2: arg2, arg3: arg3) - return viewController } - - #endif } diff --git a/Sources/SwinjectStoryboardExtensions.swift b/Sources/SwinjectStoryboardExtensions.swift index 2317726..a41ff20 100644 --- a/Sources/SwinjectStoryboardExtensions.swift +++ b/Sources/SwinjectStoryboardExtensions.swift @@ -35,7 +35,9 @@ import Swinject let wrappingClosure: (Resolver, Controller) -> () = { r, c in initCompleted(r, c as! C, arg) } - register(factory: factory, name: name) + let option = SwinjectStoryboardOption(controllerType: controllerType) + _register(Controller.self, factory: factory, name: name, option: option) + .initCompleted(wrappingClosure) } public func storyboardInitCompletedArgs(_ controllerType: C.Type, @@ -53,7 +55,9 @@ import Swinject let wrappingClosure: (Resolver, Controller) -> () = { r, c in initCompleted(r, c as! C, arg1, arg2) } - register(factory: factory, name: name) + let option = SwinjectStoryboardOption(controllerType: controllerType) + _register(Controller.self, factory: factory, name: name, option: option) + .initCompleted(wrappingClosure) } public func storyboardInitCompletedArgs(_ controllerType: C.Type, @@ -73,13 +77,10 @@ import Swinject let wrappingClosure: (Resolver, Controller) -> () = { r, c in initCompleted(r, c as! C, arg1, arg2, arg3) } - register(factory: factory, name: name) - } - - private func register(factory: FactoryType, name: String?) { let option = SwinjectStoryboardOption(controllerType: controllerType) _register(Controller.self, factory: factory, name: name, option: option) .initCompleted(wrappingClosure) } + } #endif From ab284825dd93141eb160600c44e6aff8573fd0cb Mon Sep 17 00:00:00 2001 From: Malkevych Bohdan Date: Fri, 11 Aug 2017 14:43:21 +0300 Subject: [PATCH 06/21] Updated Readme --- README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/README.md b/README.md index e5ff2dc..1ebe4b1 100644 --- a/README.md +++ b/README.md @@ -219,6 +219,30 @@ container.register(Animal.self) { _ in Cat(name: "Mimi") } If you implicitly instantiate `UIWindow` and its root view controller, the registrations setup for "Main" storyboard can be shared with the referenced storyboard since `defaultContainer` is configured in `setup` method. +### Arguments +if you want pass some arguments you can do in this way: + +1) Register VC +```swift +let container = SwinjectStoryboard.defaultContainer +container.storyboardInitCompleted(AnimalViewController.self) { r, c, arg1: Int, arg2: SomeValue in + c.animal = r.resolve(Animal.self) + c.countAnimals = arg1 + c.someValue = arg2 +} +container.register(Animal.self) { _ in Cat(name: "Mimi") } +``` + +2) Resolve VC +```swift +let sb = SwinjectStoryboard.create( + name: "Animals", bundle: nil, container: container) +let firstArg: Int = 5 +let secondArg: SomeValue = SomeValue() +let catController = sb.instantiateViewController(withIdentifier: "SomeIdentifier", arg1: firstArg, arg2: secondArg) as! AnimalViewController +``` + + ## Credits SwinjectStoryboard is inspired by: From f582e1b7190a3a4d504b361a076a7323c4f697a9 Mon Sep 17 00:00:00 2001 From: Malkevych Bohdan Date: Fri, 11 Aug 2017 14:51:02 +0300 Subject: [PATCH 07/21] Fixed readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1ebe4b1..497579f 100644 --- a/README.md +++ b/README.md @@ -220,7 +220,7 @@ container.register(Animal.self) { _ in Cat(name: "Mimi") } If you implicitly instantiate `UIWindow` and its root view controller, the registrations setup for "Main" storyboard can be shared with the referenced storyboard since `defaultContainer` is configured in `setup` method. ### Arguments -if you want pass some arguments you can do in this way: +if you want to pass some arguments, you can do it in such way: 1) Register VC ```swift From 7cfd87ea1993d0ad48c859c517ca92814857afdf Mon Sep 17 00:00:00 2001 From: Andrey Bogushev Date: Mon, 30 Jul 2018 23:42:23 +0300 Subject: [PATCH 08/21] Fixed arguments retaining while using 'storyboardInitCompletedArgs' family methods. --- Sources/SwinjectStoryboardExtensions.swift | 46 ++++++---------------- 1 file changed, 12 insertions(+), 34 deletions(-) diff --git a/Sources/SwinjectStoryboardExtensions.swift b/Sources/SwinjectStoryboardExtensions.swift index a41ff20..fa413f3 100644 --- a/Sources/SwinjectStoryboardExtensions.swift +++ b/Sources/SwinjectStoryboardExtensions.swift @@ -25,62 +25,40 @@ import Swinject public func storyboardInitCompletedArg(_ controllerType: C.Type, name: String? = nil, initCompleted: @escaping (Resolver, C, Arg) -> ()) { - var arg: Arg! - let factory = { (_: Resolver, controller: Controller, - argLocal: Arg) -> Container.Controller in - arg = argLocal - return controller - } - - let wrappingClosure: (Resolver, Controller) -> () = { r, c in + let factory = { (r: Resolver, c: Controller, + arg) -> Container.Controller in initCompleted(r, c as! C, arg) + return c } + let option = SwinjectStoryboardOption(controllerType: controllerType) _register(Controller.self, factory: factory, name: name, option: option) - .initCompleted(wrappingClosure) } public func storyboardInitCompletedArgs(_ controllerType: C.Type, name: String? = nil, initCompleted: @escaping (Resolver, C, Arg1, Arg2) -> ()) { - var arg1: Arg1! - var arg2: Arg2! - let factory = { (_: Resolver, controller: Controller, - argLocal1: Arg1, argLocal2: Arg2) -> Container.Controller in - arg1 = argLocal1 - arg2 = argLocal2 - return controller - } - - let wrappingClosure: (Resolver, Controller) -> () = { r, c in + let factory = { (r: Resolver, c: Controller, + arg1: Arg1, arg2: Arg2) -> Container.Controller in initCompleted(r, c as! C, arg1, arg2) + return c } + let option = SwinjectStoryboardOption(controllerType: controllerType) _register(Controller.self, factory: factory, name: name, option: option) - .initCompleted(wrappingClosure) } public func storyboardInitCompletedArgs(_ controllerType: C.Type, name: String? = nil, initCompleted: @escaping (Resolver, C, Arg1, Arg2, Arg3) -> ()) { - var arg1: Arg1! - var arg2: Arg2! - var arg3: Arg3! - let factory = { (_: Resolver, controller: Controller, - argLocal1: Arg1, argLocal2: Arg2, argLocal3: Arg3) -> Container.Controller in - arg1 = argLocal1 - arg2 = argLocal2 - arg3 = argLocal3 - return controller - } - - let wrappingClosure: (Resolver, Controller) -> () = { r, c in + let factory = { (r: Resolver, c: Controller, + arg1: Arg1, arg2: Arg2, arg3: Arg3) -> Container.Controller in initCompleted(r, c as! C, arg1, arg2, arg3) + return c } + let option = SwinjectStoryboardOption(controllerType: controllerType) _register(Controller.self, factory: factory, name: name, option: option) - .initCompleted(wrappingClosure) } - } #endif From f9267d202f0e90fd093f68aab1d14e6aa25acab0 Mon Sep 17 00:00:00 2001 From: Andrey Bogushev Date: Tue, 31 Jul 2018 00:11:53 +0300 Subject: [PATCH 09/21] Fixed missed argument type. --- Sources/SwinjectStoryboardExtensions.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SwinjectStoryboardExtensions.swift b/Sources/SwinjectStoryboardExtensions.swift index fa413f3..bd5108f 100644 --- a/Sources/SwinjectStoryboardExtensions.swift +++ b/Sources/SwinjectStoryboardExtensions.swift @@ -26,7 +26,7 @@ import Swinject public func storyboardInitCompletedArg(_ controllerType: C.Type, name: String? = nil, initCompleted: @escaping (Resolver, C, Arg) -> ()) { let factory = { (r: Resolver, c: Controller, - arg) -> Container.Controller in + arg: Arg) -> Container.Controller in initCompleted(r, c as! C, arg) return c } From ffd633009abd247c06d62a6c66132e9f94d5ca81 Mon Sep 17 00:00:00 2001 From: Andrey Bogushev Date: Tue, 31 Jul 2018 02:05:12 +0300 Subject: [PATCH 10/21] Fix compilation on OSX --- Cartfile.resolved | 4 +- Sources/SwinjectStoryboard.swift | 16 ++-- SwinjectStoryboard.xcodeproj/project.pbxproj | 81 +++++++------------- 3 files changed, 36 insertions(+), 65 deletions(-) diff --git a/Cartfile.resolved b/Cartfile.resolved index 9a803c0..db37aa7 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,3 +1 @@ -github "Quick/Nimble" "v6.1.0" -github "Quick/Quick" "v1.1.0" -github "Swinject/Swinject" "2.1.0" +github "Swinject/Swinject" "2.4.1" diff --git a/Sources/SwinjectStoryboard.swift b/Sources/SwinjectStoryboard.swift index 8c9409a..07c211a 100644 --- a/Sources/SwinjectStoryboard.swift +++ b/Sources/SwinjectStoryboard.swift @@ -98,8 +98,8 @@ public class SwinjectStoryboard: _SwinjectStoryboardBase, SwinjectStoryboardProt // https://github.com/Swinject/Swinject/issues/10 if let container = container.value as? _Resolver { let option = SwinjectStoryboardOption(controllerType: type(of: viewController)) - typealias FactoryType = (Resolver, Container.Controller) -> Container.Controller - let _ = container._resolve(name: registrationName, option: option) { (factory: FactoryType) in factory(self.container.value, viewController) } + typealias FactoryType = (Resolver, Container.Controller) -> Any + let _ = container._resolve(name: registrationName, option: option) { (factory: FactoryType) in factory(self.container.value, viewController) as Any } as Container.Controller? } else { fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") } @@ -172,8 +172,8 @@ extension SwinjectStoryboard { if let container = container.value as? _Resolver { let option = SwinjectStoryboardOption(controllerType: type(of: viewController)) - typealias FactoryType = (Resolver, Container.Controller, Arg) -> Container.Controller - let _ = container._resolve(name: registrationName, option: option) { (factory: FactoryType) in factory(self.container.value, viewController, arg) } + typealias FactoryType = (Resolver, Container.Controller, Arg) -> Any + let _ = container._resolve(name: registrationName, option: option) { (factory: FactoryType) in factory(self.container.value, viewController, arg) as Any } as Container.Controller? } else { fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") } @@ -191,8 +191,8 @@ extension SwinjectStoryboard { if let container = container.value as? _Resolver { let option = SwinjectStoryboardOption(controllerType: type(of: viewController)) - typealias FactoryType = (Resolver, Container.Controller, Arg1, Arg2) -> Container.Controller - let _ = container._resolve(name: registrationName, option: option) { (factory: FactoryType) in factory(self.container.value, viewController, arg1, arg2) } + typealias FactoryType = (Resolver, Container.Controller, Arg1, Arg2) -> Any + let _ = container._resolve(name: registrationName, option: option) { (factory: FactoryType) in factory(self.container.value, viewController, arg1, arg2) as Any } as Container.Controller? } else { fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") } @@ -211,8 +211,8 @@ extension SwinjectStoryboard { if let container = container.value as? _Resolver { let option = SwinjectStoryboardOption(controllerType: type(of: viewController)) - typealias FactoryType = (Resolver, Container.Controller, Arg1, Arg2, Arg3) -> Container.Controller - let _ = container._resolve(name: registrationName, option: option) { (factory: FactoryType) in factory(self.container.value, viewController, arg1, arg2, arg3) } + typealias FactoryType = (Resolver, Container.Controller, Arg1, Arg2, Arg3) -> Any + let _ = container._resolve(name: registrationName, option: option) { (factory: FactoryType) in factory(self.container.value, viewController, arg1, arg2, arg3) as Any } as Container.Controller? } else { fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") } diff --git a/SwinjectStoryboard.xcodeproj/project.pbxproj b/SwinjectStoryboard.xcodeproj/project.pbxproj index 3679310..6df209c 100644 --- a/SwinjectStoryboard.xcodeproj/project.pbxproj +++ b/SwinjectStoryboard.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 55640989210FCFD600AFFA8F /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55640987210FCFCC00AFFA8F /* Swinject.framework */; }; 983DFEA51CDB410D00D39731 /* Container+SwinjectStoryboard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 983DFE9F1CDB410D00D39731 /* Container+SwinjectStoryboard.swift */; }; 983DFEA61CDB410D00D39731 /* Container+SwinjectStoryboard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 983DFE9F1CDB410D00D39731 /* Container+SwinjectStoryboard.swift */; }; 983DFEA71CDB410D00D39731 /* Container+SwinjectStoryboard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 983DFE9F1CDB410D00D39731 /* Container+SwinjectStoryboard.swift */; }; @@ -112,24 +113,6 @@ CD6073911EBB3E8C00BE2167 /* Storyboard1.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CD6073901EBB3E8C00BE2167 /* Storyboard1.storyboard */; }; CD6073931EBB3F1400BE2167 /* RelationshipReference2.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CD6073921EBB3F1400BE2167 /* RelationshipReference2.storyboard */; }; CD6073951EBB3F6200BE2167 /* RelationshipReference1.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CD6073941EBB3F6200BE2167 /* RelationshipReference1.storyboard */; }; - CDA864931EA9F17A00293FEC /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CDA864921EA9F17A00293FEC /* Swinject.framework */; }; - CDA864951EA9F19400293FEC /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CDA864941EA9F19400293FEC /* Swinject.framework */; }; - CDA864971EA9F1A000293FEC /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CDA864961EA9F1A000293FEC /* Swinject.framework */; }; - CDA8649A1EA9F1B600293FEC /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CDA864981EA9F1B600293FEC /* Nimble.framework */; }; - CDA8649B1EA9F1B600293FEC /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CDA864991EA9F1B600293FEC /* Quick.framework */; }; - CDA864A41EA9F22900293FEC /* Nimble.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = CDA864981EA9F1B600293FEC /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - CDA864A51EA9F22900293FEC /* Quick.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = CDA864991EA9F1B600293FEC /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - CDA864A81EA9F23200293FEC /* Swinject.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = CDA864921EA9F17A00293FEC /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - CDA864AB1EA9F25C00293FEC /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CDA864AA1EA9F25C00293FEC /* Quick.framework */; }; - CDA864AE1EA9F27100293FEC /* Quick.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = CDA864AA1EA9F25C00293FEC /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - CDA864B01EA9F27200293FEC /* Swinject.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = CDA864941EA9F19400293FEC /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - CDA864B21EA9F28E00293FEC /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CDA864B11EA9F28E00293FEC /* Nimble.framework */; }; - CDA864B31EA9F29100293FEC /* Nimble.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = CDA864B11EA9F28E00293FEC /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - CDA864B61EA9F29E00293FEC /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CDA864B41EA9F29E00293FEC /* Nimble.framework */; }; - CDA864B71EA9F29E00293FEC /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CDA864B51EA9F29E00293FEC /* Quick.framework */; }; - CDA864B91EA9F2A600293FEC /* Nimble.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = CDA864B41EA9F29E00293FEC /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - CDA864BA1EA9F2A600293FEC /* Quick.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = CDA864B51EA9F29E00293FEC /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - CDA864BB1EA9F2AA00293FEC /* Swinject.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = CDA864961EA9F1A000293FEC /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -163,9 +146,6 @@ dstPath = ""; dstSubfolderSpec = 10; files = ( - CDA864A41EA9F22900293FEC /* Nimble.framework in CopyFiles */, - CDA864A51EA9F22900293FEC /* Quick.framework in CopyFiles */, - CDA864A81EA9F23200293FEC /* Swinject.framework in CopyFiles */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -175,9 +155,6 @@ dstPath = ""; dstSubfolderSpec = 10; files = ( - CDA864B31EA9F29100293FEC /* Nimble.framework in CopyFiles */, - CDA864AE1EA9F27100293FEC /* Quick.framework in CopyFiles */, - CDA864B01EA9F27200293FEC /* Swinject.framework in CopyFiles */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -187,15 +164,13 @@ dstPath = ""; dstSubfolderSpec = 10; files = ( - CDA864B91EA9F2A600293FEC /* Nimble.framework in CopyFiles */, - CDA864BA1EA9F2A600293FEC /* Quick.framework in CopyFiles */, - CDA864BB1EA9F2AA00293FEC /* Swinject.framework in CopyFiles */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 55640987210FCFCC00AFFA8F /* Swinject.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Swinject.framework; path = Carthage/Build/iOS/Swinject.framework; sourceTree = ""; }; 983DFE9F1CDB410D00D39731 /* Container+SwinjectStoryboard.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Container+SwinjectStoryboard.swift"; sourceTree = ""; }; 983DFEA01CDB410D00D39731 /* Storyboard+Swizzling.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Storyboard+Swizzling.swift"; sourceTree = ""; }; 983DFEA11CDB410D00D39731 /* SwinjectStoryboard.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwinjectStoryboard.swift; sourceTree = ""; }; @@ -281,15 +256,6 @@ CD6073901EBB3E8C00BE2167 /* Storyboard1.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Storyboard1.storyboard; sourceTree = ""; }; CD6073921EBB3F1400BE2167 /* RelationshipReference2.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = RelationshipReference2.storyboard; sourceTree = ""; }; CD6073941EBB3F6200BE2167 /* RelationshipReference1.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = RelationshipReference1.storyboard; sourceTree = ""; }; - CDA864921EA9F17A00293FEC /* Swinject.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Swinject.framework; path = Carthage/Build/iOS/Swinject.framework; sourceTree = ""; }; - CDA864941EA9F19400293FEC /* Swinject.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Swinject.framework; path = Carthage/Build/Mac/Swinject.framework; sourceTree = ""; }; - CDA864961EA9F1A000293FEC /* Swinject.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Swinject.framework; path = Carthage/Build/tvOS/Swinject.framework; sourceTree = ""; }; - CDA864981EA9F1B600293FEC /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = Carthage/Build/iOS/Nimble.framework; sourceTree = ""; }; - CDA864991EA9F1B600293FEC /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quick.framework; path = Carthage/Build/iOS/Quick.framework; sourceTree = ""; }; - CDA864AA1EA9F25C00293FEC /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quick.framework; path = Carthage/Build/Mac/Quick.framework; sourceTree = ""; }; - CDA864B11EA9F28E00293FEC /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = Carthage/Build/Mac/Nimble.framework; sourceTree = ""; }; - CDA864B41EA9F29E00293FEC /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = Carthage/Build/tvOS/Nimble.framework; sourceTree = ""; }; - CDA864B51EA9F29E00293FEC /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quick.framework; path = Carthage/Build/tvOS/Quick.framework; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -297,7 +263,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - CDA864931EA9F17A00293FEC /* Swinject.framework in Frameworks */, + 55640989210FCFD600AFFA8F /* Swinject.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -305,8 +271,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - CDA8649A1EA9F1B600293FEC /* Nimble.framework in Frameworks */, - CDA8649B1EA9F1B600293FEC /* Quick.framework in Frameworks */, 985904111CDB0AA700275E4A /* SwinjectStoryboard.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -315,7 +279,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - CDA864951EA9F19400293FEC /* Swinject.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -323,8 +286,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - CDA864B21EA9F28E00293FEC /* Nimble.framework in Frameworks */, - CDA864AB1EA9F25C00293FEC /* Quick.framework in Frameworks */, 98D562821CDB173500DECDC0 /* SwinjectStoryboard.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -333,7 +294,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - CDA864971EA9F1A000293FEC /* Swinject.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -341,8 +301,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - CDA864B61EA9F29E00293FEC /* Nimble.framework in Frameworks */, - CDA864B71EA9F29E00293FEC /* Quick.framework in Frameworks */, 98D5629E1CDB19AB00DECDC0 /* SwinjectStoryboard.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -613,15 +571,7 @@ CDA864911EA9F17900293FEC /* Frameworks */ = { isa = PBXGroup; children = ( - CDA864B41EA9F29E00293FEC /* Nimble.framework */, - CDA864B51EA9F29E00293FEC /* Quick.framework */, - CDA864B11EA9F28E00293FEC /* Nimble.framework */, - CDA864AA1EA9F25C00293FEC /* Quick.framework */, - CDA864981EA9F1B600293FEC /* Nimble.framework */, - CDA864991EA9F1B600293FEC /* Quick.framework */, - CDA864961EA9F1A000293FEC /* Swinject.framework */, - CDA864941EA9F19400293FEC /* Swinject.framework */, - CDA864921EA9F17A00293FEC /* Swinject.framework */, + 55640987210FCFCC00AFFA8F /* Swinject.framework */, ); name = Frameworks; sourceTree = ""; @@ -667,6 +617,7 @@ 985904021CDB0AA700275E4A /* Frameworks */, 985904031CDB0AA700275E4A /* Headers */, 985904041CDB0AA700275E4A /* Resources */, + 5564098A210FCFDF00AFFA8F /* ShellScript */, ); buildRules = ( ); @@ -894,6 +845,24 @@ }; /* End PBXResourcesBuildPhase section */ +/* Begin PBXShellScriptBuildPhase section */ + 5564098A210FCFDF00AFFA8F /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "$(SRCROOT)/Carthage/Build/iOS/Swinject.framework", + ); + outputPaths = ( + "$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/Swinkect.framework", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "/usr/local/bin/carthage copy-frameworks"; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ 985904011CDB0AA700275E4A /* Sources */ = { isa = PBXSourcesBuildPhase; @@ -1084,10 +1053,12 @@ "$(inherited)", "$(PROJECT_DIR)/Carthage/Build/iOS", ); + GCC_TREAT_WARNINGS_AS_ERRORS = NO; INFOPLIST_FILE = Sources/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.el-eleven.SwinjectStoryboard"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_TREAT_WARNINGS_AS_ERRORS = NO; }; name = Debug; }; @@ -1103,9 +1074,11 @@ "$(inherited)", "$(PROJECT_DIR)/Carthage/Build/iOS", ); + GCC_TREAT_WARNINGS_AS_ERRORS = NO; INFOPLIST_FILE = Sources/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.el-eleven.SwinjectStoryboard"; + SWIFT_TREAT_WARNINGS_AS_ERRORS = NO; }; name = Release; }; From 679e157889193073b9d130881409d10ab22620f9 Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 31 Jul 2018 11:22:03 +0300 Subject: [PATCH 11/21] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 99a87dd..5f90a8f 100644 --- a/README.md +++ b/README.md @@ -227,7 +227,7 @@ if you want to pass some arguments, you can do it in such way: 1) Register VC ```swift let container = SwinjectStoryboard.defaultContainer -container.storyboardInitCompleted(AnimalViewController.self) { r, c, arg1: Int, arg2: SomeValue in +container.storyboardInitCompletedArgs(AnimalViewController.self) { r, c, arg1: Int, arg2: SomeValue in c.animal = r.resolve(Animal.self) c.countAnimals = arg1 c.someValue = arg2 From 8543be2b06fb0138164f5d9cfb0d20e0691a9fad Mon Sep 17 00:00:00 2001 From: Andrey Bogushev Date: Tue, 31 Jul 2018 11:24:08 +0300 Subject: [PATCH 12/21] Added Nimble and Quick to Cartfile. --- Cartfile | 2 ++ Cartfile.resolved | 2 ++ Sources/SwinjectStoryboardExtensions.swift | 9 +++------ SwinjectStoryboard.xcodeproj/project.pbxproj | 14 +++++++++++++- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/Cartfile b/Cartfile index 5dec7e5..29dd252 100644 --- a/Cartfile +++ b/Cartfile @@ -1 +1,3 @@ github "Swinject/Swinject" ~> 2.0 +github "Quick/Nimble" +github "Quick/Quick" diff --git a/Cartfile.resolved b/Cartfile.resolved index db37aa7..f910353 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1 +1,3 @@ +github "Quick/Nimble" "v7.1.3" +github "Quick/Quick" "v1.3.1" github "Swinject/Swinject" "2.4.1" diff --git a/Sources/SwinjectStoryboardExtensions.swift b/Sources/SwinjectStoryboardExtensions.swift index bd5108f..796df8d 100644 --- a/Sources/SwinjectStoryboardExtensions.swift +++ b/Sources/SwinjectStoryboardExtensions.swift @@ -25,8 +25,7 @@ import Swinject public func storyboardInitCompletedArg(_ controllerType: C.Type, name: String? = nil, initCompleted: @escaping (Resolver, C, Arg) -> ()) { - let factory = { (r: Resolver, c: Controller, - arg: Arg) -> Container.Controller in + let factory = { (r: Resolver, c: Controller, arg: Arg) -> Container.Controller in initCompleted(r, c as! C, arg) return c } @@ -38,8 +37,7 @@ import Swinject public func storyboardInitCompletedArgs(_ controllerType: C.Type, name: String? = nil, initCompleted: @escaping (Resolver, C, Arg1, Arg2) -> ()) { - let factory = { (r: Resolver, c: Controller, - arg1: Arg1, arg2: Arg2) -> Container.Controller in + let factory = { (r: Resolver, c: Controller, arg1: Arg1, arg2: Arg2) -> Container.Controller in initCompleted(r, c as! C, arg1, arg2) return c } @@ -51,8 +49,7 @@ import Swinject public func storyboardInitCompletedArgs(_ controllerType: C.Type, name: String? = nil, initCompleted: @escaping (Resolver, C, Arg1, Arg2, Arg3) -> ()) { - let factory = { (r: Resolver, c: Controller, - arg1: Arg1, arg2: Arg2, arg3: Arg3) -> Container.Controller in + let factory = { (r: Resolver, c: Controller, arg1: Arg1, arg2: Arg2, arg3: Arg3) -> Container.Controller in initCompleted(r, c as! C, arg1, arg2, arg3) return c } diff --git a/SwinjectStoryboard.xcodeproj/project.pbxproj b/SwinjectStoryboard.xcodeproj/project.pbxproj index 6df209c..1152cf8 100644 --- a/SwinjectStoryboard.xcodeproj/project.pbxproj +++ b/SwinjectStoryboard.xcodeproj/project.pbxproj @@ -8,6 +8,8 @@ /* Begin PBXBuildFile section */ 55640989210FCFD600AFFA8F /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55640987210FCFCC00AFFA8F /* Swinject.framework */; }; + 5564098D21104F6200AFFA8F /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5564098B21104F6200AFFA8F /* Quick.framework */; }; + 5564098E21104F6200AFFA8F /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5564098C21104F6200AFFA8F /* Nimble.framework */; }; 983DFEA51CDB410D00D39731 /* Container+SwinjectStoryboard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 983DFE9F1CDB410D00D39731 /* Container+SwinjectStoryboard.swift */; }; 983DFEA61CDB410D00D39731 /* Container+SwinjectStoryboard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 983DFE9F1CDB410D00D39731 /* Container+SwinjectStoryboard.swift */; }; 983DFEA71CDB410D00D39731 /* Container+SwinjectStoryboard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 983DFE9F1CDB410D00D39731 /* Container+SwinjectStoryboard.swift */; }; @@ -171,6 +173,8 @@ /* Begin PBXFileReference section */ 55640987210FCFCC00AFFA8F /* Swinject.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Swinject.framework; path = Carthage/Build/iOS/Swinject.framework; sourceTree = ""; }; + 5564098B21104F6200AFFA8F /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quick.framework; path = Carthage/Build/iOS/Quick.framework; sourceTree = ""; }; + 5564098C21104F6200AFFA8F /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = Carthage/Build/iOS/Nimble.framework; sourceTree = ""; }; 983DFE9F1CDB410D00D39731 /* Container+SwinjectStoryboard.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Container+SwinjectStoryboard.swift"; sourceTree = ""; }; 983DFEA01CDB410D00D39731 /* Storyboard+Swizzling.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Storyboard+Swizzling.swift"; sourceTree = ""; }; 983DFEA11CDB410D00D39731 /* SwinjectStoryboard.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwinjectStoryboard.swift; sourceTree = ""; }; @@ -263,6 +267,8 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 5564098E21104F6200AFFA8F /* Nimble.framework in Frameworks */, + 5564098D21104F6200AFFA8F /* Quick.framework in Frameworks */, 55640989210FCFD600AFFA8F /* Swinject.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -571,6 +577,8 @@ CDA864911EA9F17900293FEC /* Frameworks */ = { isa = PBXGroup; children = ( + 5564098C21104F6200AFFA8F /* Nimble.framework */, + 5564098B21104F6200AFFA8F /* Quick.framework */, 55640987210FCFCC00AFFA8F /* Swinject.framework */, ); name = Frameworks; @@ -853,9 +861,13 @@ ); inputPaths = ( "$(SRCROOT)/Carthage/Build/iOS/Swinject.framework", + "$(SRCROOT)/Carthage/Build/iOS/Quick.framework", + "$(SRCROOT)/Carthage/Build/iOS/Nimble.framework", ); outputPaths = ( - "$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/Swinkect.framework", + "$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/Swinject.framework", + "$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/Quick.framework", + "$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/Nimble.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; From c144701f6c6026e39567e5b9dd13bb0f65f5ef9f Mon Sep 17 00:00:00 2001 From: Andrey Bogushev Date: Tue, 31 Jul 2018 11:54:44 +0300 Subject: [PATCH 13/21] Fixed OSX Compilation. --- Sources/SwinjectStoryboard.swift | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Sources/SwinjectStoryboard.swift b/Sources/SwinjectStoryboard.swift index e38f132..68a0b83 100644 --- a/Sources/SwinjectStoryboard.swift +++ b/Sources/SwinjectStoryboard.swift @@ -104,8 +104,9 @@ public class SwinjectStoryboard: _SwinjectStoryboardBase, SwinjectStoryboardProt // https://github.com/Swinject/Swinject/issues/10 if let container = container.value as? _Resolver { let option = SwinjectStoryboardOption(controllerType: type(of: viewController)) - typealias FactoryType = (Resolver, Container.Controller) -> Any - let _ = container._resolve(name: registrationName, option: option) { (factory: FactoryType) in factory(self.container.value, viewController) as Any } as Container.Controller? + typealias FactoryType = ((Resolver, Container.Controller)) -> Any + + let _ = container._resolve(name: registrationName, option: option) { (factory: FactoryType) in factory((self.container.value, viewController)) as Any } as Container.Controller? } else { fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") } @@ -214,8 +215,8 @@ extension SwinjectStoryboard { if let container = container.value as? _Resolver { let option = SwinjectStoryboardOption(controllerType: type(of: viewController)) - typealias FactoryType = (Resolver, Container.Controller, Arg) -> Any - let _ = container._resolve(name: registrationName, option: option) { (factory: FactoryType) in factory(self.container.value, viewController, arg) as Any } as Container.Controller? + typealias FactoryType = ((Resolver, Container.Controller, Arg)) -> Any + let _ = container._resolve(name: registrationName, option: option) { (factory: FactoryType) in factory((self.container.value, viewController, arg)) as Any } as Container.Controller? } else { fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") } @@ -233,8 +234,8 @@ extension SwinjectStoryboard { if let container = container.value as? _Resolver { let option = SwinjectStoryboardOption(controllerType: type(of: viewController)) - typealias FactoryType = (Resolver, Container.Controller, Arg1, Arg2) -> Any - let _ = container._resolve(name: registrationName, option: option) { (factory: FactoryType) in factory(self.container.value, viewController, arg1, arg2) as Any } as Container.Controller? + typealias FactoryType = ((Resolver, Container.Controller, Arg1, Arg2)) -> Any + let _ = container._resolve(name: registrationName, option: option) { (factory: FactoryType) in factory((self.container.value, viewController, arg1, arg2)) as Any } as Container.Controller? } else { fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") } @@ -253,8 +254,8 @@ extension SwinjectStoryboard { if let container = container.value as? _Resolver { let option = SwinjectStoryboardOption(controllerType: type(of: viewController)) - typealias FactoryType = (Resolver, Container.Controller, Arg1, Arg2, Arg3) -> Any - let _ = container._resolve(name: registrationName, option: option) { (factory: FactoryType) in factory(self.container.value, viewController, arg1, arg2, arg3) as Any } as Container.Controller? + typealias FactoryType = ((Resolver, Container.Controller, Arg1, Arg2, Arg3)) -> Any + let _ = container._resolve(name: registrationName, option: option) { (factory: FactoryType) in factory((self.container.value, viewController, arg1, arg2, arg3)) as Any } as Container.Controller? } else { fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") } From cac17fb72ec79bc45fd7741de65d9433421309b0 Mon Sep 17 00:00:00 2001 From: Andrey Bogushev Date: Tue, 31 Jul 2018 12:45:58 +0300 Subject: [PATCH 14/21] Fixed tests. --- SwinjectStoryboard.xcodeproj/project.pbxproj | 55 ++++++++++---------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/SwinjectStoryboard.xcodeproj/project.pbxproj b/SwinjectStoryboard.xcodeproj/project.pbxproj index 6169a2a..8ba5c2b 100644 --- a/SwinjectStoryboard.xcodeproj/project.pbxproj +++ b/SwinjectStoryboard.xcodeproj/project.pbxproj @@ -10,6 +10,15 @@ 55640989210FCFD600AFFA8F /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55640987210FCFCC00AFFA8F /* Swinject.framework */; }; 5564098D21104F6200AFFA8F /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5564098B21104F6200AFFA8F /* Quick.framework */; }; 5564098E21104F6200AFFA8F /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5564098C21104F6200AFFA8F /* Nimble.framework */; }; + 5564098F2110658E00AFFA8F /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5564098C21104F6200AFFA8F /* Nimble.framework */; }; + 556409902110658E00AFFA8F /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5564098B21104F6200AFFA8F /* Quick.framework */; }; + 556409912110658E00AFFA8F /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55640987210FCFCC00AFFA8F /* Swinject.framework */; }; + 556409922110664700AFFA8F /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5564098C21104F6200AFFA8F /* Nimble.framework */; }; + 556409932110664800AFFA8F /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5564098B21104F6200AFFA8F /* Quick.framework */; }; + 556409942110664800AFFA8F /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55640987210FCFCC00AFFA8F /* Swinject.framework */; }; + 556409952110664E00AFFA8F /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5564098C21104F6200AFFA8F /* Nimble.framework */; }; + 556409962110664E00AFFA8F /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5564098B21104F6200AFFA8F /* Quick.framework */; }; + 556409972110664E00AFFA8F /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55640987210FCFCC00AFFA8F /* Swinject.framework */; }; 983DFEA51CDB410D00D39731 /* Container+SwinjectStoryboard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 983DFE9F1CDB410D00D39731 /* Container+SwinjectStoryboard.swift */; }; 983DFEA61CDB410D00D39731 /* Container+SwinjectStoryboard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 983DFE9F1CDB410D00D39731 /* Container+SwinjectStoryboard.swift */; }; 983DFEA71CDB410D00D39731 /* Container+SwinjectStoryboard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 983DFE9F1CDB410D00D39731 /* Container+SwinjectStoryboard.swift */; }; @@ -109,24 +118,6 @@ CD6073911EBB3E8C00BE2167 /* Storyboard1.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CD6073901EBB3E8C00BE2167 /* Storyboard1.storyboard */; }; CD6073931EBB3F1400BE2167 /* RelationshipReference2.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CD6073921EBB3F1400BE2167 /* RelationshipReference2.storyboard */; }; CD6073951EBB3F6200BE2167 /* RelationshipReference1.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CD6073941EBB3F6200BE2167 /* RelationshipReference1.storyboard */; }; - CDA864931EA9F17A00293FEC /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CDA864921EA9F17A00293FEC /* Swinject.framework */; }; - CDA864951EA9F19400293FEC /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CDA864941EA9F19400293FEC /* Swinject.framework */; }; - CDA864971EA9F1A000293FEC /* Swinject.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CDA864961EA9F1A000293FEC /* Swinject.framework */; }; - CDA8649A1EA9F1B600293FEC /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CDA864981EA9F1B600293FEC /* Nimble.framework */; }; - CDA8649B1EA9F1B600293FEC /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CDA864991EA9F1B600293FEC /* Quick.framework */; }; - CDA864A41EA9F22900293FEC /* Nimble.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = CDA864981EA9F1B600293FEC /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - CDA864A51EA9F22900293FEC /* Quick.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = CDA864991EA9F1B600293FEC /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - CDA864A81EA9F23200293FEC /* Swinject.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = CDA864921EA9F17A00293FEC /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - CDA864AB1EA9F25C00293FEC /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CDA864AA1EA9F25C00293FEC /* Quick.framework */; }; - CDA864AE1EA9F27100293FEC /* Quick.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = CDA864AA1EA9F25C00293FEC /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - CDA864B01EA9F27200293FEC /* Swinject.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = CDA864941EA9F19400293FEC /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - CDA864B21EA9F28E00293FEC /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CDA864B11EA9F28E00293FEC /* Nimble.framework */; }; - CDA864B31EA9F29100293FEC /* Nimble.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = CDA864B11EA9F28E00293FEC /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - CDA864B61EA9F29E00293FEC /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CDA864B41EA9F29E00293FEC /* Nimble.framework */; }; - CDA864B71EA9F29E00293FEC /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CDA864B51EA9F29E00293FEC /* Quick.framework */; }; - CDA864B91EA9F2A600293FEC /* Nimble.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = CDA864B41EA9F29E00293FEC /* Nimble.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - CDA864BA1EA9F2A600293FEC /* Quick.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = CDA864B51EA9F29E00293FEC /* Quick.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - CDA864BB1EA9F2AA00293FEC /* Swinject.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = CDA864961EA9F1A000293FEC /* Swinject.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; FF492DA61EDA490F0081A4A7 /* SwinjectStoryboard+SetUp.m in Sources */ = {isa = PBXBuildFile; fileRef = FF492DA21EDA490F0081A4A7 /* SwinjectStoryboard+SetUp.m */; }; FF492DA71EDA490F0081A4A7 /* SwinjectStoryboard+SetUp.m in Sources */ = {isa = PBXBuildFile; fileRef = FF492DA21EDA490F0081A4A7 /* SwinjectStoryboard+SetUp.m */; }; FF492DA81EDA490F0081A4A7 /* SwinjectStoryboard+SetUp.m in Sources */ = {isa = PBXBuildFile; fileRef = FF492DA21EDA490F0081A4A7 /* SwinjectStoryboard+SetUp.m */; }; @@ -282,15 +273,6 @@ CD6073901EBB3E8C00BE2167 /* Storyboard1.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Storyboard1.storyboard; sourceTree = ""; }; CD6073921EBB3F1400BE2167 /* RelationshipReference2.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = RelationshipReference2.storyboard; sourceTree = ""; }; CD6073941EBB3F6200BE2167 /* RelationshipReference1.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = RelationshipReference1.storyboard; sourceTree = ""; }; - CDA864921EA9F17A00293FEC /* Swinject.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Swinject.framework; path = Carthage/Build/iOS/Swinject.framework; sourceTree = ""; }; - CDA864941EA9F19400293FEC /* Swinject.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Swinject.framework; path = Carthage/Build/Mac/Swinject.framework; sourceTree = ""; }; - CDA864961EA9F1A000293FEC /* Swinject.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Swinject.framework; path = Carthage/Build/tvOS/Swinject.framework; sourceTree = ""; }; - CDA864981EA9F1B600293FEC /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = Carthage/Build/iOS/Nimble.framework; sourceTree = ""; }; - CDA864991EA9F1B600293FEC /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quick.framework; path = Carthage/Build/iOS/Quick.framework; sourceTree = ""; }; - CDA864AA1EA9F25C00293FEC /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quick.framework; path = Carthage/Build/Mac/Quick.framework; sourceTree = ""; }; - CDA864B11EA9F28E00293FEC /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = Carthage/Build/Mac/Nimble.framework; sourceTree = ""; }; - CDA864B41EA9F29E00293FEC /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = Carthage/Build/tvOS/Nimble.framework; sourceTree = ""; }; - CDA864B51EA9F29E00293FEC /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quick.framework; path = Carthage/Build/tvOS/Quick.framework; sourceTree = ""; }; FF492DA21EDA490F0081A4A7 /* SwinjectStoryboard+SetUp.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "SwinjectStoryboard+SetUp.m"; sourceTree = ""; }; FF492DAF1EDA65D90081A4A7 /* NSStoryboard+Swizzling.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSStoryboard+Swizzling.h"; sourceTree = ""; }; FF492DB01EDA65D90081A4A7 /* NSStoryboard+Swizzling.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSStoryboard+Swizzling.m"; sourceTree = ""; }; @@ -315,6 +297,9 @@ buildActionMask = 2147483647; files = ( 985904111CDB0AA700275E4A /* SwinjectStoryboard.framework in Frameworks */, + 5564098F2110658E00AFFA8F /* Nimble.framework in Frameworks */, + 556409902110658E00AFFA8F /* Quick.framework in Frameworks */, + 556409912110658E00AFFA8F /* Swinject.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -330,6 +315,9 @@ buildActionMask = 2147483647; files = ( 98D562821CDB173500DECDC0 /* SwinjectStoryboard.framework in Frameworks */, + 556409922110664700AFFA8F /* Nimble.framework in Frameworks */, + 556409932110664800AFFA8F /* Quick.framework in Frameworks */, + 556409942110664800AFFA8F /* Swinject.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -345,6 +333,9 @@ buildActionMask = 2147483647; files = ( 98D5629E1CDB19AB00DECDC0 /* SwinjectStoryboard.framework in Frameworks */, + 556409952110664E00AFFA8F /* Nimble.framework in Frameworks */, + 556409962110664E00AFFA8F /* Quick.framework in Frameworks */, + 556409972110664E00AFFA8F /* Swinject.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1155,6 +1146,7 @@ ); INFOPLIST_FILE = Tests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 9.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks $(FRAMEWORK_SEARCH_PATHS)"; PRODUCT_BUNDLE_IDENTIFIER = "com.el-eleven.SwinjectStoryboardTests"; PRODUCT_NAME = "$(PROJECT_NAME)Tests"; }; @@ -1170,6 +1162,7 @@ ); INFOPLIST_FILE = Tests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 9.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks $(FRAMEWORK_SEARCH_PATHS)"; PRODUCT_BUNDLE_IDENTIFIER = "com.el-eleven.SwinjectStoryboardTests"; PRODUCT_NAME = "$(PROJECT_NAME)Tests"; }; @@ -1219,8 +1212,10 @@ FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/Carthage/Build/Mac", + "$(PROJECT_DIR)/Carthage/Build/iOS", ); INFOPLIST_FILE = Tests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks $(FRAMEWORK_SEARCH_PATHS)"; MACOSX_DEPLOYMENT_TARGET = 10.11; PRODUCT_BUNDLE_IDENTIFIER = "com.el-eleven.SwinjectStoryboardTests"; PRODUCT_NAME = "$(PROJECT_NAME)Tests"; @@ -1234,8 +1229,10 @@ FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/Carthage/Build/Mac", + "$(PROJECT_DIR)/Carthage/Build/iOS", ); INFOPLIST_FILE = Tests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks $(FRAMEWORK_SEARCH_PATHS)"; MACOSX_DEPLOYMENT_TARGET = 10.11; PRODUCT_BUNDLE_IDENTIFIER = "com.el-eleven.SwinjectStoryboardTests"; PRODUCT_NAME = "$(PROJECT_NAME)Tests"; @@ -1291,8 +1288,10 @@ FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/Carthage/Build/tvOS", + "$(PROJECT_DIR)/Carthage/Build/iOS", ); INFOPLIST_FILE = Tests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks $(FRAMEWORK_SEARCH_PATHS)"; PRODUCT_BUNDLE_IDENTIFIER = "com.el-eleven.SwinjectStoryboardTests"; PRODUCT_NAME = "$(PROJECT_NAME)Tests"; }; @@ -1306,8 +1305,10 @@ FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/Carthage/Build/tvOS", + "$(PROJECT_DIR)/Carthage/Build/iOS", ); INFOPLIST_FILE = Tests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks $(FRAMEWORK_SEARCH_PATHS)"; PRODUCT_BUNDLE_IDENTIFIER = "com.el-eleven.SwinjectStoryboardTests"; PRODUCT_NAME = "$(PROJECT_NAME)Tests"; }; From 33f45f123ac1f5649ed78c5e0305ac91afef83f9 Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 2 Aug 2018 23:52:06 +0300 Subject: [PATCH 15/21] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5f90a8f..92a0ab7 100644 --- a/README.md +++ b/README.md @@ -227,7 +227,7 @@ if you want to pass some arguments, you can do it in such way: 1) Register VC ```swift let container = SwinjectStoryboard.defaultContainer -container.storyboardInitCompletedArgs(AnimalViewController.self) { r, c, arg1: Int, arg2: SomeValue in +container.storyboardInitCompletedArgs(AnimalViewController.self) { (r, c, arg1: Int, arg2: SomeValue) in c.animal = r.resolve(Animal.self) c.countAnimals = arg1 c.someValue = arg2 From 14ae7ecf601d0299acf0a9d20d81163a0f0db938 Mon Sep 17 00:00:00 2001 From: Andrey Bogushev Date: Fri, 21 Sep 2018 16:02:57 +0300 Subject: [PATCH 16/21] Update dependency version on 'Swinject'. --- SwinjectStoryboard.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SwinjectStoryboard.podspec b/SwinjectStoryboard.podspec index 63a22df..2154150 100644 --- a/SwinjectStoryboard.podspec +++ b/SwinjectStoryboard.podspec @@ -17,6 +17,6 @@ Pod::Spec.new do |s| s.ios.deployment_target = '8.0' s.osx.deployment_target = '10.10' s.tvos.deployment_target = '9.0' - s.dependency 'Swinject', '~> 2.4' + s.dependency 'Swinject', '~> 2.5' s.requires_arc = true end From c9644a5e1dfee636b30c105c3d131ea984adb3b2 Mon Sep 17 00:00:00 2001 From: aayers-agrible Date: Mon, 22 Oct 2018 14:32:41 -0500 Subject: [PATCH 17/21] added autogenerated code for arguments calls, added tests --- Cartfile | 2 - Sources/SwinjectStoryboard.Arguments.erb | 143 ++++++++++ Sources/SwinjectStoryboard.Arguments.swift | 276 +++++++++++++++++++ Sources/SwinjectStoryboard.swift | 97 ------- Sources/SwinjectStoryboardExtensions.swift | 61 ---- SwinjectStoryboard.xcodeproj/project.pbxproj | 20 +- Tests/OSX/SwinjectStoryboardSpec.swift | 84 ++++++ Tests/iOS-tvOS/SwinjectStoryboardSpec.swift | 85 ++++++ script/gencode | 8 + 9 files changed, 608 insertions(+), 168 deletions(-) create mode 100644 Sources/SwinjectStoryboard.Arguments.erb create mode 100644 Sources/SwinjectStoryboard.Arguments.swift delete mode 100644 Sources/SwinjectStoryboardExtensions.swift create mode 100755 script/gencode diff --git a/Cartfile b/Cartfile index 7f87ebe..2c824ee 100644 --- a/Cartfile +++ b/Cartfile @@ -1,3 +1 @@ github "Swinject/Swinject" ~> 2.4 -github "Quick/Nimble" -github "Quick/Quick" \ No newline at end of file diff --git a/Sources/SwinjectStoryboard.Arguments.erb b/Sources/SwinjectStoryboard.Arguments.erb new file mode 100644 index 0000000..bfe0845 --- /dev/null +++ b/Sources/SwinjectStoryboard.Arguments.erb @@ -0,0 +1,143 @@ +// +// Created by Andrew Ayers on 10/22/18 +// Copyright © 2018 Swinject Contributors. All rights reserved. +// + +// +// NOTICE: +// +// SwinjectStoryboard.Arguments.swift is generated from SwinjectStoryboard.Arguments.erb by ERB. +// Do NOT modify SwinjectStoryboard.Arguments.swift directly. +// Instead, modify SwinjectStoryboard.Arguments.erb and run `script/gencode` at the project root directory to generate the code. +// + +<% arg_count = 3 %> + +import Swinject +#if os(iOS) || os(tvOS) +extension SwinjectStoryboard { +<% (1..arg_count).each do |i| %> +<% arg_types = (1..i).map { |n| "Arg#{n}" }.join(", ") %> +<% arg_description = i == 1 ? "#{i} argument" : "#{i} arguments" %> + + private func injectDependency<<%= arg_types %>>(to viewController: UIViewController, arguments: (<%= arg_types %>) ) { + guard !viewController.wasInjected else { return } + defer { viewController.wasInjected = true } + + let registrationName = viewController.swinjectRegistrationName + + if let container = container.value as? _Resolver { + let option = SwinjectStoryboardOption(controllerType: type(of: viewController)) + typealias FactoryType = ((Resolver, Container.Controller, (<%= arg_types %>))) -> Any + let _ = container._resolve(name: registrationName, option: option) { (factory: FactoryType) in factory((self.container.value, viewController, arguments)) as Any } as Container.Controller? + } else { + fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") + } + + for child in viewController.childViewControllers { + injectDependency(to: child, arguments: arguments) + } + } +<% end %> + +<% (1..arg_count).each do |i| %> +<% arg_types = (1..i).map { |n| "Arg#{n}" }.join(", ") %> +<% arg_description = i == 1 ? "#{i} argument" : "#{i} arguments" %> + + public func instantiateViewController<<%= arg_types %>>(withIdentifier identifier: String, + arguments: (<%= arg_types %>)) -> UIViewController { + let viewController = loadViewController(with: identifier) + injectDependency(to: viewController, arguments: arguments) + return viewController + } + +<% end %> + + private func loadViewController(with identifier: String) -> UIViewController { + SwinjectStoryboard.pushInstantiatingStoryboard(self) + let viewController = super.instantiateViewController(withIdentifier: identifier) + SwinjectStoryboard.popInstantiatingStoryboard() + return viewController + } +} +#endif + +#if os(OSX) +extension SwinjectStoryboard { + <% (1..arg_count).each do |i| %> + <% arg_types = (1..i).map { |n| "Arg#{n}" }.join(", ") %> + <% arg_description = i == 1 ? "#{i} argument" : "#{i} arguments" %> + + private func injectDependency<<%= arg_types %>>(to viewController: NSViewController, arguments: (<%= arg_types %>) ) { + guard !viewController.wasInjected else { return } + defer { viewController.wasInjected = true } + + let registrationName = viewController.swinjectRegistrationName + + if let container = container.value as? _Resolver { + let option = SwinjectStoryboardOption(controllerType: type(of: viewController)) + typealias FactoryType = ((Resolver, Container.Controller, (<%= arg_types %>))) -> Any + let _ = container._resolve(name: registrationName, option: option) { (factory: FactoryType) in factory((self.container.value, viewController, arguments)) as Any } as Container.Controller? + } else { + fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") + } + + for child in viewController.childViewControllers { + injectDependency(to: child, arguments: arguments) + } + } + <% end %> + + <% (1..arg_count).each do |i| %> + <% arg_types = (1..i).map { |n| "Arg#{n}" }.join(", ") %> + <% arg_description = i == 1 ? "#{i} argument" : "#{i} arguments" %> + + public func instantiateController<<%= arg_types %>>(withIdentifier identifier: NSStoryboard.SceneIdentifier, + arguments: (<%= arg_types %>)) -> NSViewController { + let viewController = loadController(with: identifier) as! NSViewController + injectDependency(to: viewController, arguments: arguments) + return viewController + } + + <% end %> + + private func loadController(with identifier: NSStoryboard.SceneIdentifier) -> Any { + SwinjectStoryboard.pushInstantiatingStoryboard(self) + let viewController = super.instantiateController(withIdentifier: identifier) + SwinjectStoryboard.popInstantiatingStoryboard() + return viewController + } +} +#endif + +#if os(iOS) || os(OSX) || os(tvOS) +extension Container { +<% (1..arg_count).each do |i| %> +<% arg_types = (1..i).map { |n| "Arg#{n}" }.join(", ") %> +<% arg_description = i == 1 ? "#{i} argument" : "#{i} arguments" %> + /// Adds a registration of the specified view or window controller that is configured in a storyboard. + /// + /// - Note: Do NOT explicitly resolve the controller registered by this method. + /// The controller is intended to be resolved by `SwinjectStoryboard` implicitly. + /// + /// - Parameters: + /// - controllerType: The controller type to register as a service type. + /// The type is `UIViewController` in iOS, `NSViewController` or `NSWindowController` in OS X. + /// - name: A registration name, which is used to differenciate from other registrations + /// that have the same view or window controller type. + /// - initCompleted: A closure to specifiy how the dependencies of the view or window controller are injected. + /// It is invoked by the `Container` when the view or window controller is instantiated by `SwinjectStoryboard`. + + public func storyboardInitCompletedArg>(_ controllerType: C.Type, + name: String? = nil, initCompleted: @escaping (Resolver, C, (<%= arg_types %>)) -> ()) { + let factory = { (r: Resolver, c: Controller, arguments: (<%= arg_types %>)) -> Container.Controller in + initCompleted(r, c as! C, arguments) + return c + } + + let option = SwinjectStoryboardOption(controllerType: controllerType) + _register(Controller.self, factory: factory, name: name, option: option) + } +<% end %> +} +#endif diff --git a/Sources/SwinjectStoryboard.Arguments.swift b/Sources/SwinjectStoryboard.Arguments.swift new file mode 100644 index 0000000..27f3886 --- /dev/null +++ b/Sources/SwinjectStoryboard.Arguments.swift @@ -0,0 +1,276 @@ +// +// Created by Andrew Ayers on 10/22/18 +// Copyright © 2018 Swinject Contributors. All rights reserved. +// + +// +// NOTICE: +// +// SwinjectStoryboard.Arguments.swift is generated from SwinjectStoryboard.Arguments.erb by ERB. +// Do NOT modify SwinjectStoryboard.Arguments.swift directly. +// Instead, modify SwinjectStoryboard.Arguments.erb and run `script/gencode` at the project root directory to generate the code. +// + + +import Swinject +#if os(iOS) || os(tvOS) +extension SwinjectStoryboard { + + private func injectDependency(to viewController: UIViewController, arguments: (Arg1) ) { + guard !viewController.wasInjected else { return } + defer { viewController.wasInjected = true } + + let registrationName = viewController.swinjectRegistrationName + + if let container = container.value as? _Resolver { + let option = SwinjectStoryboardOption(controllerType: type(of: viewController)) + typealias FactoryType = ((Resolver, Container.Controller, (Arg1))) -> Any + let _ = container._resolve(name: registrationName, option: option) { (factory: FactoryType) in factory((self.container.value, viewController, arguments)) as Any } as Container.Controller? + } else { + fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") + } + + for child in viewController.childViewControllers { + injectDependency(to: child, arguments: arguments) + } + } + + private func injectDependency(to viewController: UIViewController, arguments: (Arg1, Arg2) ) { + guard !viewController.wasInjected else { return } + defer { viewController.wasInjected = true } + + let registrationName = viewController.swinjectRegistrationName + + if let container = container.value as? _Resolver { + let option = SwinjectStoryboardOption(controllerType: type(of: viewController)) + typealias FactoryType = ((Resolver, Container.Controller, (Arg1, Arg2))) -> Any + let _ = container._resolve(name: registrationName, option: option) { (factory: FactoryType) in factory((self.container.value, viewController, arguments)) as Any } as Container.Controller? + } else { + fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") + } + + for child in viewController.childViewControllers { + injectDependency(to: child, arguments: arguments) + } + } + + private func injectDependency(to viewController: UIViewController, arguments: (Arg1, Arg2, Arg3) ) { + guard !viewController.wasInjected else { return } + defer { viewController.wasInjected = true } + + let registrationName = viewController.swinjectRegistrationName + + if let container = container.value as? _Resolver { + let option = SwinjectStoryboardOption(controllerType: type(of: viewController)) + typealias FactoryType = ((Resolver, Container.Controller, (Arg1, Arg2, Arg3))) -> Any + let _ = container._resolve(name: registrationName, option: option) { (factory: FactoryType) in factory((self.container.value, viewController, arguments)) as Any } as Container.Controller? + } else { + fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") + } + + for child in viewController.childViewControllers { + injectDependency(to: child, arguments: arguments) + } + } + + + public func instantiateViewController(withIdentifier identifier: String, + arguments: (Arg1)) -> UIViewController { + let viewController = loadViewController(with: identifier) + injectDependency(to: viewController, arguments: arguments) + return viewController + } + + + public func instantiateViewController(withIdentifier identifier: String, + arguments: (Arg1, Arg2)) -> UIViewController { + let viewController = loadViewController(with: identifier) + injectDependency(to: viewController, arguments: arguments) + return viewController + } + + + public func instantiateViewController(withIdentifier identifier: String, + arguments: (Arg1, Arg2, Arg3)) -> UIViewController { + let viewController = loadViewController(with: identifier) + injectDependency(to: viewController, arguments: arguments) + return viewController + } + + + private func loadViewController(with identifier: String) -> UIViewController { + SwinjectStoryboard.pushInstantiatingStoryboard(self) + let viewController = super.instantiateViewController(withIdentifier: identifier) + SwinjectStoryboard.popInstantiatingStoryboard() + return viewController + } +} +#endif + +#if os(OSX) +extension SwinjectStoryboard { + + private func injectDependency(to viewController: NSViewController, arguments: (Arg1) ) { + guard !viewController.wasInjected else { return } + defer { viewController.wasInjected = true } + + let registrationName = viewController.swinjectRegistrationName + + if let container = container.value as? _Resolver { + let option = SwinjectStoryboardOption(controllerType: type(of: viewController)) + typealias FactoryType = ((Resolver, Container.Controller, (Arg1))) -> Any + let _ = container._resolve(name: registrationName, option: option) { (factory: FactoryType) in factory((self.container.value, viewController, arguments)) as Any } as Container.Controller? + } else { + fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") + } + + for child in viewController.childViewControllers { + injectDependency(to: child, arguments: arguments) + } + } + + private func injectDependency(to viewController: NSViewController, arguments: (Arg1, Arg2) ) { + guard !viewController.wasInjected else { return } + defer { viewController.wasInjected = true } + + let registrationName = viewController.swinjectRegistrationName + + if let container = container.value as? _Resolver { + let option = SwinjectStoryboardOption(controllerType: type(of: viewController)) + typealias FactoryType = ((Resolver, Container.Controller, (Arg1, Arg2))) -> Any + let _ = container._resolve(name: registrationName, option: option) { (factory: FactoryType) in factory((self.container.value, viewController, arguments)) as Any } as Container.Controller? + } else { + fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") + } + + for child in viewController.childViewControllers { + injectDependency(to: child, arguments: arguments) + } + } + + private func injectDependency(to viewController: NSViewController, arguments: (Arg1, Arg2, Arg3) ) { + guard !viewController.wasInjected else { return } + defer { viewController.wasInjected = true } + + let registrationName = viewController.swinjectRegistrationName + + if let container = container.value as? _Resolver { + let option = SwinjectStoryboardOption(controllerType: type(of: viewController)) + typealias FactoryType = ((Resolver, Container.Controller, (Arg1, Arg2, Arg3))) -> Any + let _ = container._resolve(name: registrationName, option: option) { (factory: FactoryType) in factory((self.container.value, viewController, arguments)) as Any } as Container.Controller? + } else { + fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") + } + + for child in viewController.childViewControllers { + injectDependency(to: child, arguments: arguments) + } + } + + + public func instantiateController(withIdentifier identifier: NSStoryboard.SceneIdentifier, + arguments: (Arg1)) -> NSViewController { + let viewController = loadController(with: identifier) as! NSViewController + injectDependency(to: viewController, arguments: arguments) + return viewController + } + + + public func instantiateController(withIdentifier identifier: NSStoryboard.SceneIdentifier, + arguments: (Arg1, Arg2)) -> NSViewController { + let viewController = loadController(with: identifier) as! NSViewController + injectDependency(to: viewController, arguments: arguments) + return viewController + } + + + public func instantiateController(withIdentifier identifier: NSStoryboard.SceneIdentifier, + arguments: (Arg1, Arg2, Arg3)) -> NSViewController { + let viewController = loadController(with: identifier) as! NSViewController + injectDependency(to: viewController, arguments: arguments) + return viewController + } + + + private func loadController(with identifier: NSStoryboard.SceneIdentifier) -> Any { + SwinjectStoryboard.pushInstantiatingStoryboard(self) + let viewController = super.instantiateController(withIdentifier: identifier) + SwinjectStoryboard.popInstantiatingStoryboard() + return viewController + } +} +#endif + +#if os(iOS) || os(OSX) || os(tvOS) +extension Container { + /// Adds a registration of the specified view or window controller that is configured in a storyboard. + /// + /// - Note: Do NOT explicitly resolve the controller registered by this method. + /// The controller is intended to be resolved by `SwinjectStoryboard` implicitly. + /// + /// - Parameters: + /// - controllerType: The controller type to register as a service type. + /// The type is `UIViewController` in iOS, `NSViewController` or `NSWindowController` in OS X. + /// - name: A registration name, which is used to differenciate from other registrations + /// that have the same view or window controller type. + /// - initCompleted: A closure to specifiy how the dependencies of the view or window controller are injected. + /// It is invoked by the `Container` when the view or window controller is instantiated by `SwinjectStoryboard`. + + public func storyboardInitCompletedArg(_ controllerType: C.Type, + name: String? = nil, initCompleted: @escaping (Resolver, C, (Arg1)) -> ()) { + let factory = { (r: Resolver, c: Controller, arguments: (Arg1)) -> Container.Controller in + initCompleted(r, c as! C, arguments) + return c + } + + let option = SwinjectStoryboardOption(controllerType: controllerType) + _register(Controller.self, factory: factory, name: name, option: option) + } + /// Adds a registration of the specified view or window controller that is configured in a storyboard. + /// + /// - Note: Do NOT explicitly resolve the controller registered by this method. + /// The controller is intended to be resolved by `SwinjectStoryboard` implicitly. + /// + /// - Parameters: + /// - controllerType: The controller type to register as a service type. + /// The type is `UIViewController` in iOS, `NSViewController` or `NSWindowController` in OS X. + /// - name: A registration name, which is used to differenciate from other registrations + /// that have the same view or window controller type. + /// - initCompleted: A closure to specifiy how the dependencies of the view or window controller are injected. + /// It is invoked by the `Container` when the view or window controller is instantiated by `SwinjectStoryboard`. + + public func storyboardInitCompletedArg(_ controllerType: C.Type, + name: String? = nil, initCompleted: @escaping (Resolver, C, (Arg1, Arg2)) -> ()) { + let factory = { (r: Resolver, c: Controller, arguments: (Arg1, Arg2)) -> Container.Controller in + initCompleted(r, c as! C, arguments) + return c + } + + let option = SwinjectStoryboardOption(controllerType: controllerType) + _register(Controller.self, factory: factory, name: name, option: option) + } + /// Adds a registration of the specified view or window controller that is configured in a storyboard. + /// + /// - Note: Do NOT explicitly resolve the controller registered by this method. + /// The controller is intended to be resolved by `SwinjectStoryboard` implicitly. + /// + /// - Parameters: + /// - controllerType: The controller type to register as a service type. + /// The type is `UIViewController` in iOS, `NSViewController` or `NSWindowController` in OS X. + /// - name: A registration name, which is used to differenciate from other registrations + /// that have the same view or window controller type. + /// - initCompleted: A closure to specifiy how the dependencies of the view or window controller are injected. + /// It is invoked by the `Container` when the view or window controller is instantiated by `SwinjectStoryboard`. + + public func storyboardInitCompletedArg(_ controllerType: C.Type, + name: String? = nil, initCompleted: @escaping (Resolver, C, (Arg1, Arg2, Arg3)) -> ()) { + let factory = { (r: Resolver, c: Controller, arguments: (Arg1, Arg2, Arg3)) -> Container.Controller in + initCompleted(r, c as! C, arguments) + return c + } + + let option = SwinjectStoryboardOption(controllerType: controllerType) + _register(Controller.self, factory: factory, name: name, option: option) + } +} +#endif diff --git a/Sources/SwinjectStoryboard.swift b/Sources/SwinjectStoryboard.swift index 68a0b83..0244702 100644 --- a/Sources/SwinjectStoryboard.swift +++ b/Sources/SwinjectStoryboard.swift @@ -201,100 +201,3 @@ public class SwinjectStoryboard: _SwinjectStoryboardBase, SwinjectStoryboardProt } #endif - - -extension SwinjectStoryboard { - - #if os(iOS) || os(tvOS) - - private func injectDependency(to viewController: UIViewController, arg: Arg) { - guard !viewController.wasInjected else { return } - defer { viewController.wasInjected = true } - - let registrationName = viewController.swinjectRegistrationName - - if let container = container.value as? _Resolver { - let option = SwinjectStoryboardOption(controllerType: type(of: viewController)) - typealias FactoryType = ((Resolver, Container.Controller, Arg)) -> Any - let _ = container._resolve(name: registrationName, option: option) { (factory: FactoryType) in factory((self.container.value, viewController, arg)) as Any } as Container.Controller? - } else { - fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") - } - - for child in viewController.childViewControllers { - injectDependency(to: child) - } - } - - private func injectDependency(to viewController: UIViewController, arg1: Arg1, arg2: Arg2) { - guard !viewController.wasInjected else { return } - defer { viewController.wasInjected = true } - - let registrationName = viewController.swinjectRegistrationName - - if let container = container.value as? _Resolver { - let option = SwinjectStoryboardOption(controllerType: type(of: viewController)) - typealias FactoryType = ((Resolver, Container.Controller, Arg1, Arg2)) -> Any - let _ = container._resolve(name: registrationName, option: option) { (factory: FactoryType) in factory((self.container.value, viewController, arg1, arg2)) as Any } as Container.Controller? - } else { - fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") - } - - for child in viewController.childViewControllers { - injectDependency(to: child) - } - } - - private func injectDependency(to viewController: UIViewController, - arg1: Arg1, arg2: Arg2, arg3: Arg3) { - guard !viewController.wasInjected else { return } - defer { viewController.wasInjected = true } - - let registrationName = viewController.swinjectRegistrationName - - if let container = container.value as? _Resolver { - let option = SwinjectStoryboardOption(controllerType: type(of: viewController)) - typealias FactoryType = ((Resolver, Container.Controller, Arg1, Arg2, Arg3)) -> Any - let _ = container._resolve(name: registrationName, option: option) { (factory: FactoryType) in factory((self.container.value, viewController, arg1, arg2, arg3)) as Any } as Container.Controller? - } else { - fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") - } - - for child in viewController.childViewControllers { - injectDependency(to: child) - } - } - - //MARK: - instantiateViewController with Args - - public func instantiateViewController(withIdentifier identifier: String, - arg: Arg) -> UIViewController { - let viewController = loadViewController(with: identifier) - injectDependency(to: viewController, arg: arg) - return viewController - } - - public func instantiateViewController(withIdentifier identifier: String, - arg1: Arg1, arg2: Arg2) -> UIViewController { - let viewController = loadViewController(with: identifier) - injectDependency(to: viewController, arg1: arg1, arg2: arg2) - return viewController - } - - public func instantiateViewController(withIdentifier identifier: String, - arg1: Arg1, arg2: Arg2, arg3: Arg3) -> UIViewController { - let viewController = loadViewController(with: identifier) - injectDependency(to: viewController, arg1: arg1, arg2: arg2, arg3: arg3) - return viewController - } - - private func loadViewController(with identifier: String) -> UIViewController { - SwinjectStoryboard.pushInstantiatingStoryboard(self) - let viewController = super.instantiateViewController(withIdentifier: identifier) - SwinjectStoryboard.popInstantiatingStoryboard() - return viewController - } - - #endif - -} diff --git a/Sources/SwinjectStoryboardExtensions.swift b/Sources/SwinjectStoryboardExtensions.swift deleted file mode 100644 index 796df8d..0000000 --- a/Sources/SwinjectStoryboardExtensions.swift +++ /dev/null @@ -1,61 +0,0 @@ -// -// SwinjectStoryboardExtensions.swift -// SwinjectStoryboard -// -// Created by Malkevych Bohdan on 10.08.17. -// Copyright © 2017 Swinject Contributors. All rights reserved. -// - -import Swinject - -#if os(iOS) || os(OSX) || os(tvOS) - extension Container { - /// Adds a registration of the specified view or window controller that is configured in a storyboard. - /// - /// - Note: Do NOT explicitly resolve the controller registered by this method. - /// The controller is intended to be resolved by `SwinjectStoryboard` implicitly. - /// - /// - Parameters: - /// - controllerType: The controller type to register as a service type. - /// The type is `UIViewController` in iOS, `NSViewController` or `NSWindowController` in OS X. - /// - name: A registration name, which is used to differenciate from other registrations - /// that have the same view or window controller type. - /// - initCompleted: A closure to specifiy how the dependencies of the view or window controller are injected. - /// It is invoked by the `Container` when the view or window controller is instantiated by `SwinjectStoryboard`. - - public func storyboardInitCompletedArg(_ controllerType: C.Type, - name: String? = nil, initCompleted: @escaping (Resolver, C, Arg) -> ()) { - let factory = { (r: Resolver, c: Controller, arg: Arg) -> Container.Controller in - initCompleted(r, c as! C, arg) - return c - } - - let option = SwinjectStoryboardOption(controllerType: controllerType) - _register(Controller.self, factory: factory, name: name, option: option) - } - - public func storyboardInitCompletedArgs(_ controllerType: C.Type, - name: String? = nil, - initCompleted: @escaping (Resolver, C, Arg1, Arg2) -> ()) { - let factory = { (r: Resolver, c: Controller, arg1: Arg1, arg2: Arg2) -> Container.Controller in - initCompleted(r, c as! C, arg1, arg2) - return c - } - - let option = SwinjectStoryboardOption(controllerType: controllerType) - _register(Controller.self, factory: factory, name: name, option: option) - } - - public func storyboardInitCompletedArgs(_ controllerType: C.Type, - name: String? = nil, - initCompleted: @escaping (Resolver, C, Arg1, Arg2, Arg3) -> ()) { - let factory = { (r: Resolver, c: Controller, arg1: Arg1, arg2: Arg2, arg3: Arg3) -> Container.Controller in - initCompleted(r, c as! C, arg1, arg2, arg3) - return c - } - - let option = SwinjectStoryboardOption(controllerType: controllerType) - _register(Controller.self, factory: factory, name: name, option: option) - } - } -#endif diff --git a/SwinjectStoryboard.xcodeproj/project.pbxproj b/SwinjectStoryboard.xcodeproj/project.pbxproj index 8ba5c2b..f70f32f 100644 --- a/SwinjectStoryboard.xcodeproj/project.pbxproj +++ b/SwinjectStoryboard.xcodeproj/project.pbxproj @@ -87,9 +87,10 @@ 98978E6A1DFC354B0046B966 /* UnavailableItems.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98978E671DFC354B0046B966 /* UnavailableItems.swift */; }; 98D562821CDB173500DECDC0 /* SwinjectStoryboard.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 98D562781CDB173500DECDC0 /* SwinjectStoryboard.framework */; }; 98D5629E1CDB19AB00DECDC0 /* SwinjectStoryboard.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 98D562941CDB19AB00DECDC0 /* SwinjectStoryboard.framework */; }; - B92E951F1F3CCEAD0051FD3E /* SwinjectStoryboardExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92E951E1F3CCEAD0051FD3E /* SwinjectStoryboardExtensions.swift */; }; - B92E95201F3CCEAD0051FD3E /* SwinjectStoryboardExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92E951E1F3CCEAD0051FD3E /* SwinjectStoryboardExtensions.swift */; }; - B92E95211F3CCEAD0051FD3E /* SwinjectStoryboardExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = B92E951E1F3CCEAD0051FD3E /* SwinjectStoryboardExtensions.swift */; }; + A16CF79D217E4C0500800AA1 /* SwinjectStoryboard.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = A16CF79B217E4C0400800AA1 /* SwinjectStoryboard.Arguments.swift */; }; + A16CF79E217E4C0500800AA1 /* SwinjectStoryboard.Arguments.erb in Resources */ = {isa = PBXBuildFile; fileRef = A16CF79C217E4C0500800AA1 /* SwinjectStoryboard.Arguments.erb */; }; + A16CF79F217E51BC00800AA1 /* SwinjectStoryboard.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = A16CF79B217E4C0400800AA1 /* SwinjectStoryboard.Arguments.swift */; }; + A16CF7A0217E51BE00800AA1 /* SwinjectStoryboard.Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = A16CF79B217E4C0400800AA1 /* SwinjectStoryboard.Arguments.swift */; }; CD2C63AA1D7864840075BC14 /* SwinjectStoryboard+StoryboardReference.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD2C63A91D7864840075BC14 /* SwinjectStoryboard+StoryboardReference.swift */; }; CD2C63AB1D7864840075BC14 /* SwinjectStoryboard+StoryboardReference.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD2C63A91D7864840075BC14 /* SwinjectStoryboard+StoryboardReference.swift */; }; CD2C63AD1D786C1F0075BC14 /* RelationshipReference1.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CD2C63AC1D786C1F0075BC14 /* RelationshipReference1.storyboard */; }; @@ -249,7 +250,8 @@ 98D562CA1CDB1E8800DECDC0 /* tvOS-Base.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = "tvOS-Base.xcconfig"; sourceTree = ""; }; 98D562CB1CDB1E8800DECDC0 /* tvOS-Framework.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = "tvOS-Framework.xcconfig"; sourceTree = ""; }; 98D562CC1CDB1E8800DECDC0 /* tvOS-StaticLibrary.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = "tvOS-StaticLibrary.xcconfig"; sourceTree = ""; }; - B92E951E1F3CCEAD0051FD3E /* SwinjectStoryboardExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwinjectStoryboardExtensions.swift; sourceTree = ""; }; + A16CF79B217E4C0400800AA1 /* SwinjectStoryboard.Arguments.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwinjectStoryboard.Arguments.swift; sourceTree = ""; }; + A16CF79C217E4C0500800AA1 /* SwinjectStoryboard.Arguments.erb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = SwinjectStoryboard.Arguments.erb; sourceTree = ""; }; CD2C63A91D7864840075BC14 /* SwinjectStoryboard+StoryboardReference.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "SwinjectStoryboard+StoryboardReference.swift"; sourceTree = ""; }; CD2C63AC1D786C1F0075BC14 /* RelationshipReference1.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = RelationshipReference1.storyboard; sourceTree = ""; }; CD2C63AE1D786CD70075BC14 /* RelationshipReference2.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = RelationshipReference2.storyboard; sourceTree = ""; }; @@ -441,6 +443,8 @@ 985904081CDB0AA700275E4A /* Sources */ = { isa = PBXGroup; children = ( + A16CF79C217E4C0500800AA1 /* SwinjectStoryboard.Arguments.erb */, + A16CF79B217E4C0400800AA1 /* SwinjectStoryboard.Arguments.swift */, 983DFEB91CDB414900D39731 /* iOS-tvOS */, 983DFEC01CDB415300D39731 /* OSX */, 983DFE9F1CDB410D00D39731 /* Container+SwinjectStoryboard.swift */, @@ -456,7 +460,6 @@ 98978E671DFC354B0046B966 /* UnavailableItems.swift */, 985904091CDB0AA700275E4A /* SwinjectStoryboard.h */, 9859040B1CDB0AA700275E4A /* Info.plist */, - B92E951E1F3CCEAD0051FD3E /* SwinjectStoryboardExtensions.swift */, ); path = Sources; sourceTree = ""; @@ -832,6 +835,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + A16CF79E217E4C0500800AA1 /* SwinjectStoryboard.Arguments.erb in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -931,10 +935,10 @@ 983DFEAB1CDB410D00D39731 /* SwinjectStoryboard.swift in Sources */, CD2C63AA1D7864840075BC14 /* SwinjectStoryboard+StoryboardReference.swift in Sources */, 983DFF0B1CDB440800D39731 /* Box.swift in Sources */, + A16CF79D217E4C0500800AA1 /* SwinjectStoryboard.Arguments.swift in Sources */, 983DFEBE1CDB414900D39731 /* _SwinjectStoryboardBase.m in Sources */, FF492DB71EDA65E30081A4A7 /* UIStoryboard+Swizzling.m in Sources */, 983DFEB41CDB410D00D39731 /* ViewController+Swinject.swift in Sources */, - B92E951F1F3CCEAD0051FD3E /* SwinjectStoryboardExtensions.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -970,9 +974,9 @@ CD2C63B01D786D6B0075BC14 /* SwinjectStoryboard+StoryboardReference.swift in Sources */, 983DFEAC1CDB410D00D39731 /* SwinjectStoryboard.swift in Sources */, 983DFF0C1CDB440800D39731 /* Box.swift in Sources */, + A16CF79F217E51BC00800AA1 /* SwinjectStoryboard.Arguments.swift in Sources */, 983DFEC41CDB415300D39731 /* _SwinjectStoryboardBase.m in Sources */, 983DFEB51CDB410D00D39731 /* ViewController+Swinject.swift in Sources */, - B92E95201F3CCEAD0051FD3E /* SwinjectStoryboardExtensions.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1009,9 +1013,9 @@ CD2C63AB1D7864840075BC14 /* SwinjectStoryboard+StoryboardReference.swift in Sources */, 983DFF0D1CDB440800D39731 /* Box.swift in Sources */, 983DFEBF1CDB414900D39731 /* _SwinjectStoryboardBase.m in Sources */, + A16CF7A0217E51BE00800AA1 /* SwinjectStoryboard.Arguments.swift in Sources */, FF492DB81EDA65E30081A4A7 /* UIStoryboard+Swizzling.m in Sources */, 983DFEB61CDB410D00D39731 /* ViewController+Swinject.swift in Sources */, - B92E95211F3CCEAD0051FD3E /* SwinjectStoryboardExtensions.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Tests/OSX/SwinjectStoryboardSpec.swift b/Tests/OSX/SwinjectStoryboardSpec.swift index be919b2..f22f04e 100644 --- a/Tests/OSX/SwinjectStoryboardSpec.swift +++ b/Tests/OSX/SwinjectStoryboardSpec.swift @@ -193,6 +193,90 @@ class SwinjectStoryboardSpec: QuickSpec { SwinjectStoryboard.defaultContainer.removeAll() } } + describe("Arguments passed through instantiate view controller") { + it("should inject data passed into a view controller - 1 arg") { + guard let container = container else { + fail() + return + } + + container.storyboardInitCompletedArg(AnimalViewController.self) { (r, c, name: (String)) in + c.animal = r.resolve(Animal.self) + // Try to use the injected name argument to set a new name on the Cat + if let cat = c.animal as? Cat { + cat.name = name + } + } + container.register(Animal.self) { _ in Cat(name: "Mimi") } + let storyboard = SwinjectStoryboard.create(name: .animals, bundle: bundle, container: container) + // Instantiate the view controller, with an extra argument of a new name for the Cat. + let animalViewController = storyboard.instantiateController(withIdentifier: .animalView, arguments: "Whiskers") as! AnimalViewController + // Assert that the name was passed through correctly. + expect(animalViewController.hasAnimal(named: "Whiskers")) == true + } + it("should inject data passed into a view controller - 2 args") { + guard let container = container else { + fail() + return + } + + container.storyboardInitCompletedArg(AnimalViewController.self) { (r, c, arguments: (String, Bool)) in + c.animal = r.resolve(Animal.self) + // Try to use the injected name argument to set a new name on the Cat + if let cat = c.animal as? Cat { + let name = arguments.0 + let sleeping = arguments.1 + cat.name = name + cat.sleeping = sleeping + } + } + container.register(Animal.self) { _ in Cat(name: "Mimi") } + let storyboard = SwinjectStoryboard.create(name: .animals, bundle: bundle, container: container) + + // Instantiate the view controller, with an extra argument of a new name for the Cat, and a new sleeping param + let animalViewController = storyboard.instantiateController(withIdentifier: .animalView, arguments: ("Whiskers", true)) as! AnimalViewController + // Assert that extra context was passed through correctly. + expect(animalViewController.hasAnimal(named: "Whiskers")) == true + guard let cat = animalViewController.animal as? Cat else { + fail() + return + } + expect(cat.sleeping)==true + } + it("should inject data passed into a view controller - 3 args") { + guard let container = container else { + fail() + return + } + + container.storyboardInitCompletedArg(AnimalViewController.self) { (r, c, arguments: (String, Bool, Food)) in + c.animal = r.resolve(Animal.self) + // Try to use the injected name argument to set a new name on the Cat + if let cat = c.animal as? Cat { + cat.name = arguments.0 + cat.sleeping = arguments.1 + cat.favoriteFood = arguments.2 + } + } + container.register(Animal.self) { _ in Cat(name: "Mimi") } + let storyboard = SwinjectStoryboard.create(name: .animals, bundle: bundle, container: container) + + let arguments: (String, Bool, Food) = ("Whiskers", true, Sushi()) + // Instantiate the view controller, with an extra argument of a new name for the Cat. + let animalViewController = storyboard.instantiateController(withIdentifier: .animalView, arguments: arguments) as! AnimalViewController + // Assert that the name was passed through correctly. + expect(animalViewController.hasAnimal(named: "Whiskers")) == true + guard let cat = animalViewController.animal as? Cat else { + fail() + return + } + expect(cat.sleeping)==true + expect(cat.favoriteFood is Sushi) == true + } + afterEach { + SwinjectStoryboard.defaultContainer.removeAll() + } + } describe("Setup") { it("calls setup function only once.") { _ = SwinjectStoryboard.create(name: .animals, bundle: bundle) diff --git a/Tests/iOS-tvOS/SwinjectStoryboardSpec.swift b/Tests/iOS-tvOS/SwinjectStoryboardSpec.swift index 3a0b03d..7a4764f 100644 --- a/Tests/iOS-tvOS/SwinjectStoryboardSpec.swift +++ b/Tests/iOS-tvOS/SwinjectStoryboardSpec.swift @@ -184,6 +184,91 @@ class SwinjectStoryboardSpec: QuickSpec { } } } + describe("Arguments passed through instantiate view controller") { + it("should inject data passed into a view controller - 1 arg") { + guard let container = container else { + fail() + return + } + + container.storyboardInitCompletedArg(AnimalViewController.self) { (r, c, name: (String)) in + c.animal = r.resolve(Animal.self) + // Try to use the injected name argument to set a new name on the Cat + if let cat = c.animal as? Cat { + cat.name = name + } + } + container.register(Animal.self) { _ in Cat(name: "Mimi") } + let storyboard = SwinjectStoryboard.create(name: "Animals", bundle: bundle, container: container) + + // Instantiate the view controller, with an extra argument of a new name for the Cat. + let animalViewController = storyboard.instantiateViewController(withIdentifier: "AnimalAsCat", arguments: "Whiskers") as! AnimalViewController + // Assert that the name was passed through correctly. + expect(animalViewController.hasAnimal(named: "Whiskers")) == true + } + it("should inject data passed into a view controller - 2 args") { + guard let container = container else { + fail() + return + } + + container.storyboardInitCompletedArg(AnimalViewController.self) { (r, c, arguments: (String, Bool)) in + c.animal = r.resolve(Animal.self) + // Try to use the injected name argument to set a new name on the Cat + if let cat = c.animal as? Cat { + let name = arguments.0 + let sleeping = arguments.1 + cat.name = name + cat.sleeping = sleeping + } + } + container.register(Animal.self) { _ in Cat(name: "Mimi") } + let storyboard = SwinjectStoryboard.create(name: "Animals", bundle: bundle, container: container) + + // Instantiate the view controller, with an extra argument of a new name for the Cat, and a new sleeping param + let animalViewController = storyboard.instantiateViewController(withIdentifier: "AnimalAsCat", arguments: ("Whiskers", true)) as! AnimalViewController + // Assert that extra context was passed through correctly. + expect(animalViewController.hasAnimal(named: "Whiskers")) == true + guard let cat = animalViewController.animal as? Cat else { + fail() + return + } + expect(cat.sleeping)==true + } + it("should inject data passed into a view controller - 3 args") { + guard let container = container else { + fail() + return + } + + container.storyboardInitCompletedArg(AnimalViewController.self) { (r, c, arguments: (String, Bool, Food)) in + c.animal = r.resolve(Animal.self) + // Try to use the injected name argument to set a new name on the Cat + if let cat = c.animal as? Cat { + cat.name = arguments.0 + cat.sleeping = arguments.1 + cat.favoriteFood = arguments.2 + } + } + container.register(Animal.self) { _ in Cat(name: "Mimi") } + let storyboard = SwinjectStoryboard.create(name: "Animals", bundle: bundle, container: container) + + let arguments: (String, Bool, Food) = ("Whiskers", true, Sushi()) + // Instantiate the view controller, with an extra argument of a new name for the Cat. + let animalViewController = storyboard.instantiateViewController(withIdentifier: "AnimalAsCat", arguments: arguments) as! AnimalViewController + // Assert that the name was passed through correctly. + expect(animalViewController.hasAnimal(named: "Whiskers")) == true + guard let cat = animalViewController.animal as? Cat else { + fail() + return + } + expect(cat.sleeping)==true + expect(cat.favoriteFood is Sushi) == true + } + afterEach { + SwinjectStoryboard.defaultContainer.removeAll() + } + } describe("Setup") { it("calls setup function only once.") { _ = SwinjectStoryboard.create(name: "Animals", bundle: bundle) diff --git a/script/gencode b/script/gencode new file mode 100755 index 0000000..fdc6e0a --- /dev/null +++ b/script/gencode @@ -0,0 +1,8 @@ +#!/bin/sh + +files="Sources/SwinjectStoryboard.Arguments" + +for file in $files; do + echo "Generating code to $file.swift" + erb -v -T 1 $file.erb > $file.swift +done From a7b8685b7d56c1eeaaa674ad319e82c934bcacb2 Mon Sep 17 00:00:00 2001 From: aayers-agrible Date: Mon, 22 Oct 2018 14:48:35 -0500 Subject: [PATCH 18/21] change source in podspec --- SwinjectStoryboard.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SwinjectStoryboard.podspec b/SwinjectStoryboard.podspec index 2154150..3ce9189 100644 --- a/SwinjectStoryboard.podspec +++ b/SwinjectStoryboard.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.homepage = "https://github.com/Swinject/SwinjectStoryboard" s.license = 'MIT' s.author = 'Swinject Contributors' - s.source = { :git => "https://github.com/SeductiveMobile/SwinjectStoryboard.git", :tag => s.version.to_s } + s.source = { :git => "https://github.com/Swinject/SwinjectStoryboard.git", :tag => s.version.to_s } core_files = 'Sources/*.{swift,m,h}' s.ios.source_files = core_files, 'Sources/iOS-tvOS/*.{swift,h,m}' From b5ef3f5f13bc54999a129e452d36968db01794d8 Mon Sep 17 00:00:00 2001 From: aayers-agrible Date: Mon, 22 Oct 2018 15:12:35 -0500 Subject: [PATCH 19/21] update readme, changed childViewControllers -> children in autogen code --- README.md | 8 ++++---- Sources/SwinjectStoryboard.Arguments.erb | 2 +- Sources/SwinjectStoryboard.Arguments.swift | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 92a0ab7..be958a0 100644 --- a/README.md +++ b/README.md @@ -227,10 +227,10 @@ if you want to pass some arguments, you can do it in such way: 1) Register VC ```swift let container = SwinjectStoryboard.defaultContainer -container.storyboardInitCompletedArgs(AnimalViewController.self) { (r, c, arg1: Int, arg2: SomeValue) in +container.storyboardInitCompletedArgs(AnimalViewController.self) { (r, c, arguments: (Int, SomeValue)) in c.animal = r.resolve(Animal.self) - c.countAnimals = arg1 - c.someValue = arg2 + c.countAnimals = arguments.0 + c.someValue = arguments.1 } container.register(Animal.self) { _ in Cat(name: "Mimi") } ``` @@ -241,7 +241,7 @@ let sb = SwinjectStoryboard.create( name: "Animals", bundle: nil, container: container) let firstArg: Int = 5 let secondArg: SomeValue = SomeValue() -let catController = sb.instantiateViewController(withIdentifier: "SomeIdentifier", arg1: firstArg, arg2: secondArg) as! AnimalViewController +let catController = sb.instantiateViewController(withIdentifier: "SomeIdentifier", arguments: (firstArg, secondArg)) as! AnimalViewController ``` diff --git a/Sources/SwinjectStoryboard.Arguments.erb b/Sources/SwinjectStoryboard.Arguments.erb index bfe0845..c40c043 100644 --- a/Sources/SwinjectStoryboard.Arguments.erb +++ b/Sources/SwinjectStoryboard.Arguments.erb @@ -34,7 +34,7 @@ extension SwinjectStoryboard { fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") } - for child in viewController.childViewControllers { + for child in viewController.children { injectDependency(to: child, arguments: arguments) } } diff --git a/Sources/SwinjectStoryboard.Arguments.swift b/Sources/SwinjectStoryboard.Arguments.swift index 27f3886..cd5e52a 100644 --- a/Sources/SwinjectStoryboard.Arguments.swift +++ b/Sources/SwinjectStoryboard.Arguments.swift @@ -30,7 +30,7 @@ extension SwinjectStoryboard { fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") } - for child in viewController.childViewControllers { + for child in viewController.children { injectDependency(to: child, arguments: arguments) } } @@ -49,7 +49,7 @@ extension SwinjectStoryboard { fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") } - for child in viewController.childViewControllers { + for child in viewController.children { injectDependency(to: child, arguments: arguments) } } @@ -68,7 +68,7 @@ extension SwinjectStoryboard { fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") } - for child in viewController.childViewControllers { + for child in viewController.children { injectDependency(to: child, arguments: arguments) } } From 581207609eaa514581cea6d3dee7ae36184307e3 Mon Sep 17 00:00:00 2001 From: aayers-agrible Date: Mon, 29 Oct 2018 11:38:16 -0500 Subject: [PATCH 20/21] Corrected children view controller naming issue --- Sources/SwinjectStoryboard.Arguments.erb | 14 ++++++- Sources/SwinjectStoryboard.Arguments.swift | 44 +++++++++++++++++++-- Tests/OSX/SwinjectStoryboardSpec.swift | 6 +-- Tests/iOS-tvOS/SwinjectStoryboardSpec.swift | 6 +-- 4 files changed, 59 insertions(+), 11 deletions(-) diff --git a/Sources/SwinjectStoryboard.Arguments.erb b/Sources/SwinjectStoryboard.Arguments.erb index c40c043..5ed3643 100644 --- a/Sources/SwinjectStoryboard.Arguments.erb +++ b/Sources/SwinjectStoryboard.Arguments.erb @@ -34,9 +34,15 @@ extension SwinjectStoryboard { fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") } + #if swift(>=4.2) for child in viewController.children { injectDependency(to: child, arguments: arguments) } + #else + for child in viewController.childViewControllers { + injectDependency(to: child, arguments: arguments) + } + #endif } <% end %> @@ -82,9 +88,15 @@ extension SwinjectStoryboard { fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") } + #if swift(>=4.2) + for child in viewController.children { + injectDependency(to: child, arguments: arguments) + } + #else for child in viewController.childViewControllers { injectDependency(to: child, arguments: arguments) } + #endif } <% end %> @@ -128,7 +140,7 @@ extension Container { /// - initCompleted: A closure to specifiy how the dependencies of the view or window controller are injected. /// It is invoked by the `Container` when the view or window controller is instantiated by `SwinjectStoryboard`. - public func storyboardInitCompletedArg>(_ controllerType: C.Type, + public func storyboardInitCompleted>(_ controllerType: C.Type, name: String? = nil, initCompleted: @escaping (Resolver, C, (<%= arg_types %>)) -> ()) { let factory = { (r: Resolver, c: Controller, arguments: (<%= arg_types %>)) -> Container.Controller in initCompleted(r, c as! C, arguments) diff --git a/Sources/SwinjectStoryboard.Arguments.swift b/Sources/SwinjectStoryboard.Arguments.swift index cd5e52a..3ef8142 100644 --- a/Sources/SwinjectStoryboard.Arguments.swift +++ b/Sources/SwinjectStoryboard.Arguments.swift @@ -30,9 +30,15 @@ extension SwinjectStoryboard { fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") } + #if swift(>=4.2) for child in viewController.children { injectDependency(to: child, arguments: arguments) } + #else + for child in viewController.childViewControllers { + injectDependency(to: child, arguments: arguments) + } + #endif } private func injectDependency(to viewController: UIViewController, arguments: (Arg1, Arg2) ) { @@ -49,9 +55,15 @@ extension SwinjectStoryboard { fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") } + #if swift(>=4.2) for child in viewController.children { injectDependency(to: child, arguments: arguments) } + #else + for child in viewController.childViewControllers { + injectDependency(to: child, arguments: arguments) + } + #endif } private func injectDependency(to viewController: UIViewController, arguments: (Arg1, Arg2, Arg3) ) { @@ -68,9 +80,15 @@ extension SwinjectStoryboard { fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") } + #if swift(>=4.2) for child in viewController.children { injectDependency(to: child, arguments: arguments) } + #else + for child in viewController.childViewControllers { + injectDependency(to: child, arguments: arguments) + } + #endif } @@ -124,9 +142,15 @@ extension SwinjectStoryboard { fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") } + #if swift(>=4.2) + for child in viewController.children { + injectDependency(to: child, arguments: arguments) + } + #else for child in viewController.childViewControllers { injectDependency(to: child, arguments: arguments) } + #endif } private func injectDependency(to viewController: NSViewController, arguments: (Arg1, Arg2) ) { @@ -138,14 +162,20 @@ extension SwinjectStoryboard { if let container = container.value as? _Resolver { let option = SwinjectStoryboardOption(controllerType: type(of: viewController)) typealias FactoryType = ((Resolver, Container.Controller, (Arg1, Arg2))) -> Any - let _ = container._resolve(name: registrationName, option: option) { (factory: FactoryType) in factory((self.container.value, viewController, arguments)) as Any } as Container.Controller? + let _ = container._resolve(name: registrationName, option: option) { (factory: FactoryType) in factory((self.contai¨ner.value, viewController, arguments)) as Any } as Container.Controller? } else { fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") } + #if swift(>=4.2) + for child in viewController.children { + injectDependency(to: child, arguments: arguments) + } + #else for child in viewController.childViewControllers { injectDependency(to: child, arguments: arguments) } + #endif } private func injectDependency(to viewController: NSViewController, arguments: (Arg1, Arg2, Arg3) ) { @@ -162,9 +192,15 @@ extension SwinjectStoryboard { fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") } + #if swift(>=4.2) + for child in viewController.children { + injectDependency(to: child, arguments: arguments) + } + #else for child in viewController.childViewControllers { injectDependency(to: child, arguments: arguments) } + #endif } @@ -216,7 +252,7 @@ extension Container { /// - initCompleted: A closure to specifiy how the dependencies of the view or window controller are injected. /// It is invoked by the `Container` when the view or window controller is instantiated by `SwinjectStoryboard`. - public func storyboardInitCompletedArg(_ controllerType: C.Type, + public func storyboardInitCompleted(_ controllerType: C.Type, name: String? = nil, initCompleted: @escaping (Resolver, C, (Arg1)) -> ()) { let factory = { (r: Resolver, c: Controller, arguments: (Arg1)) -> Container.Controller in initCompleted(r, c as! C, arguments) @@ -239,7 +275,7 @@ extension Container { /// - initCompleted: A closure to specifiy how the dependencies of the view or window controller are injected. /// It is invoked by the `Container` when the view or window controller is instantiated by `SwinjectStoryboard`. - public func storyboardInitCompletedArg(_ controllerType: C.Type, + public func storyboardInitCompleted(_ controllerType: C.Type, name: String? = nil, initCompleted: @escaping (Resolver, C, (Arg1, Arg2)) -> ()) { let factory = { (r: Resolver, c: Controller, arguments: (Arg1, Arg2)) -> Container.Controller in initCompleted(r, c as! C, arguments) @@ -262,7 +298,7 @@ extension Container { /// - initCompleted: A closure to specifiy how the dependencies of the view or window controller are injected. /// It is invoked by the `Container` when the view or window controller is instantiated by `SwinjectStoryboard`. - public func storyboardInitCompletedArg(_ controllerType: C.Type, + public func storyboardInitCompleted(_ controllerType: C.Type, name: String? = nil, initCompleted: @escaping (Resolver, C, (Arg1, Arg2, Arg3)) -> ()) { let factory = { (r: Resolver, c: Controller, arguments: (Arg1, Arg2, Arg3)) -> Container.Controller in initCompleted(r, c as! C, arguments) diff --git a/Tests/OSX/SwinjectStoryboardSpec.swift b/Tests/OSX/SwinjectStoryboardSpec.swift index 8a876a4..22868b5 100644 --- a/Tests/OSX/SwinjectStoryboardSpec.swift +++ b/Tests/OSX/SwinjectStoryboardSpec.swift @@ -205,7 +205,7 @@ class SwinjectStoryboardSpec: QuickSpec { return } - container.storyboardInitCompletedArg(AnimalViewController.self) { (r, c, name: (String)) in + container.storyboardInitCompleted(AnimalViewController.self) { (r, c, name: (String)) in c.animal = r.resolve(Animal.self) // Try to use the injected name argument to set a new name on the Cat if let cat = c.animal as? Cat { @@ -225,7 +225,7 @@ class SwinjectStoryboardSpec: QuickSpec { return } - container.storyboardInitCompletedArg(AnimalViewController.self) { (r, c, arguments: (String, Bool)) in + container.storyboardInitCompleted(AnimalViewController.self) { (r, c, arguments: (String, Bool)) in c.animal = r.resolve(Animal.self) // Try to use the injected name argument to set a new name on the Cat if let cat = c.animal as? Cat { @@ -254,7 +254,7 @@ class SwinjectStoryboardSpec: QuickSpec { return } - container.storyboardInitCompletedArg(AnimalViewController.self) { (r, c, arguments: (String, Bool, Food)) in + container.storyboardInitCompleted(AnimalViewController.self) { (r, c, arguments: (String, Bool, Food)) in c.animal = r.resolve(Animal.self) // Try to use the injected name argument to set a new name on the Cat if let cat = c.animal as? Cat { diff --git a/Tests/iOS-tvOS/SwinjectStoryboardSpec.swift b/Tests/iOS-tvOS/SwinjectStoryboardSpec.swift index 6c93ddf..ac3598e 100644 --- a/Tests/iOS-tvOS/SwinjectStoryboardSpec.swift +++ b/Tests/iOS-tvOS/SwinjectStoryboardSpec.swift @@ -196,7 +196,7 @@ class SwinjectStoryboardSpec: QuickSpec { return } - container.storyboardInitCompletedArg(AnimalViewController.self) { (r, c, name: (String)) in + container.storyboardInitCompleted(AnimalViewController.self) { (r, c, name: (String)) in c.animal = r.resolve(Animal.self) // Try to use the injected name argument to set a new name on the Cat if let cat = c.animal as? Cat { @@ -217,7 +217,7 @@ class SwinjectStoryboardSpec: QuickSpec { return } - container.storyboardInitCompletedArg(AnimalViewController.self) { (r, c, arguments: (String, Bool)) in + container.storyboardInitCompleted(AnimalViewController.self) { (r, c, arguments: (String, Bool)) in c.animal = r.resolve(Animal.self) // Try to use the injected name argument to set a new name on the Cat if let cat = c.animal as? Cat { @@ -246,7 +246,7 @@ class SwinjectStoryboardSpec: QuickSpec { return } - container.storyboardInitCompletedArg(AnimalViewController.self) { (r, c, arguments: (String, Bool, Food)) in + container.storyboardInitCompleted(AnimalViewController.self) { (r, c, arguments: (String, Bool, Food)) in c.animal = r.resolve(Animal.self) // Try to use the injected name argument to set a new name on the Cat if let cat = c.animal as? Cat { From 2b91fe7e5c0d6d0f56509e355a9994aec1a378e5 Mon Sep 17 00:00:00 2001 From: aayers-agrible Date: Mon, 29 Oct 2018 12:34:13 -0500 Subject: [PATCH 21/21] Travis could not resolve Swinject dependency in podspec, bumping down to 2.4 --- Sources/SwinjectStoryboard.Arguments.swift | 2 +- SwinjectStoryboard.podspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/SwinjectStoryboard.Arguments.swift b/Sources/SwinjectStoryboard.Arguments.swift index 3ef8142..073564e 100644 --- a/Sources/SwinjectStoryboard.Arguments.swift +++ b/Sources/SwinjectStoryboard.Arguments.swift @@ -162,7 +162,7 @@ extension SwinjectStoryboard { if let container = container.value as? _Resolver { let option = SwinjectStoryboardOption(controllerType: type(of: viewController)) typealias FactoryType = ((Resolver, Container.Controller, (Arg1, Arg2))) -> Any - let _ = container._resolve(name: registrationName, option: option) { (factory: FactoryType) in factory((self.contai¨ner.value, viewController, arguments)) as Any } as Container.Controller? + let _ = container._resolve(name: registrationName, option: option) { (factory: FactoryType) in factory((self.container.value, viewController, arguments)) as Any } as Container.Controller? } else { fatalError("A type conforming Resolver protocol must conform _Resolver protocol too.") } diff --git a/SwinjectStoryboard.podspec b/SwinjectStoryboard.podspec index 9628b93..dc48aed 100644 --- a/SwinjectStoryboard.podspec +++ b/SwinjectStoryboard.podspec @@ -17,6 +17,6 @@ Pod::Spec.new do |s| s.ios.deployment_target = '8.0' s.osx.deployment_target = '10.10' s.tvos.deployment_target = '9.0' - s.dependency 'Swinject', '~> 2.5' + s.dependency 'Swinject', '~> 2.4' s.requires_arc = true end