From 40cef64ad6c55f9832cf08111655feeb0b650e5b Mon Sep 17 00:00:00 2001 From: Justin Kolb Date: Thu, 28 Jan 2016 21:54:59 -0600 Subject: [PATCH] Added new form of method where the factory allows configuration of the object at an earlier point in time in the request. Removed unused test target. Added LICENSE and README.md so they are visible when the project file is open. --- FieryCrucible.xcodeproj/project.pbxproj | 136 +----------------- .../xcschemes/FieryCrucible.xcscheme | 10 -- FieryCrucible/DependencyFactory.swift | 31 ++-- FieryCrucible/FieryCrucible.h | 14 +- FieryCrucible/Info.plist | 4 +- FieryCrucibleTests/FieryCrucibleTests.swift | 30 ---- FieryCrucibleTests/Info.plist | 24 ---- LICENSE | 19 +++ README.md | 22 ++- 9 files changed, 65 insertions(+), 225 deletions(-) delete mode 100644 FieryCrucibleTests/FieryCrucibleTests.swift delete mode 100644 FieryCrucibleTests/Info.plist create mode 100644 LICENSE diff --git a/FieryCrucible.xcodeproj/project.pbxproj b/FieryCrucible.xcodeproj/project.pbxproj index d43984e..4f26760 100644 --- a/FieryCrucible.xcodeproj/project.pbxproj +++ b/FieryCrucible.xcodeproj/project.pbxproj @@ -8,29 +8,16 @@ /* Begin PBXBuildFile section */ E53405B01A3020CE00A474C1 /* FieryCrucible.h in Headers */ = {isa = PBXBuildFile; fileRef = E53405AF1A3020CE00A474C1 /* FieryCrucible.h */; settings = {ATTRIBUTES = (Public, ); }; }; - E53405B61A3020CF00A474C1 /* FieryCrucible.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E53405AA1A3020CE00A474C1 /* FieryCrucible.framework */; }; - E53405BD1A3020CF00A474C1 /* FieryCrucibleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E53405BC1A3020CF00A474C1 /* FieryCrucibleTests.swift */; }; E5A928C81A32C0B60071875D /* DependencyFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = E5A928C71A32C0B60071875D /* DependencyFactory.swift */; }; /* End PBXBuildFile section */ -/* Begin PBXContainerItemProxy section */ - E53405B71A3020CF00A474C1 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = E53405A11A3020CE00A474C1 /* Project object */; - proxyType = 1; - remoteGlobalIDString = E53405A91A3020CE00A474C1; - remoteInfo = FieryCrucible; - }; -/* End PBXContainerItemProxy section */ - /* Begin PBXFileReference section */ E53405AA1A3020CE00A474C1 /* FieryCrucible.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = FieryCrucible.framework; sourceTree = BUILT_PRODUCTS_DIR; }; E53405AE1A3020CE00A474C1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; E53405AF1A3020CE00A474C1 /* FieryCrucible.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FieryCrucible.h; sourceTree = ""; }; - E53405B51A3020CF00A474C1 /* FieryCrucibleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = FieryCrucibleTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - E53405BB1A3020CF00A474C1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - E53405BC1A3020CF00A474C1 /* FieryCrucibleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FieryCrucibleTests.swift; sourceTree = ""; }; E5A928C71A32C0B60071875D /* DependencyFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DependencyFactory.swift; sourceTree = ""; }; + E5F98A491C5B13300072BAF8 /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = ""; }; + E5F98A4B1C5B13370072BAF8 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -41,22 +28,15 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - E53405B21A3020CF00A474C1 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - E53405B61A3020CF00A474C1 /* FieryCrucible.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ E53405A01A3020CE00A474C1 = { isa = PBXGroup; children = ( + E5F98A4B1C5B13370072BAF8 /* README.md */, + E5F98A491C5B13300072BAF8 /* LICENSE */, E53405AC1A3020CE00A474C1 /* FieryCrucible */, - E53405B91A3020CF00A474C1 /* FieryCrucibleTests */, E53405AB1A3020CE00A474C1 /* Products */, ); sourceTree = ""; @@ -65,7 +45,6 @@ isa = PBXGroup; children = ( E53405AA1A3020CE00A474C1 /* FieryCrucible.framework */, - E53405B51A3020CF00A474C1 /* FieryCrucibleTests.xctest */, ); name = Products; sourceTree = ""; @@ -88,23 +67,6 @@ name = "Supporting Files"; sourceTree = ""; }; - E53405B91A3020CF00A474C1 /* FieryCrucibleTests */ = { - isa = PBXGroup; - children = ( - E53405BC1A3020CF00A474C1 /* FieryCrucibleTests.swift */, - E53405BA1A3020CF00A474C1 /* Supporting Files */, - ); - path = FieryCrucibleTests; - sourceTree = ""; - }; - E53405BA1A3020CF00A474C1 /* Supporting Files */ = { - isa = PBXGroup; - children = ( - E53405BB1A3020CF00A474C1 /* Info.plist */, - ); - name = "Supporting Files"; - sourceTree = ""; - }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ @@ -137,24 +99,6 @@ productReference = E53405AA1A3020CE00A474C1 /* FieryCrucible.framework */; productType = "com.apple.product-type.framework"; }; - E53405B41A3020CF00A474C1 /* FieryCrucibleTests */ = { - isa = PBXNativeTarget; - buildConfigurationList = E53405C31A3020CF00A474C1 /* Build configuration list for PBXNativeTarget "FieryCrucibleTests" */; - buildPhases = ( - E53405B11A3020CF00A474C1 /* Sources */, - E53405B21A3020CF00A474C1 /* Frameworks */, - E53405B31A3020CF00A474C1 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - E53405B81A3020CF00A474C1 /* PBXTargetDependency */, - ); - name = FieryCrucibleTests; - productName = FieryCrucibleTests; - productReference = E53405B51A3020CF00A474C1 /* FieryCrucibleTests.xctest */; - productType = "com.apple.product-type.bundle.unit-test"; - }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ @@ -168,9 +112,6 @@ E53405A91A3020CE00A474C1 = { CreatedOnToolsVersion = 6.1.1; }; - E53405B41A3020CF00A474C1 = { - CreatedOnToolsVersion = 6.1.1; - }; }; }; buildConfigurationList = E53405A41A3020CE00A474C1 /* Build configuration list for PBXProject "FieryCrucible" */; @@ -186,7 +127,6 @@ projectRoot = ""; targets = ( E53405A91A3020CE00A474C1 /* FieryCrucible */, - E53405B41A3020CF00A474C1 /* FieryCrucibleTests */, ); }; /* End PBXProject section */ @@ -199,13 +139,6 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - E53405B31A3020CF00A474C1 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ @@ -217,24 +150,8 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - E53405B11A3020CF00A474C1 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - E53405BD1A3020CF00A474C1 /* FieryCrucibleTests.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; /* End PBXSourcesBuildPhase section */ -/* Begin PBXTargetDependency section */ - E53405B81A3020CF00A474C1 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = E53405A91A3020CE00A474C1 /* FieryCrucible */; - targetProxy = E53405B71A3020CF00A474C1 /* PBXContainerItemProxy */; - }; -/* End PBXTargetDependency section */ - /* Begin XCBuildConfiguration section */ E53405BE1A3020CF00A474C1 /* Debug */ = { isa = XCBuildConfiguration; @@ -272,7 +189,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.1; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -312,7 +229,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.1; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; @@ -355,38 +272,6 @@ }; name = Release; }; - E53405C41A3020CF00A474C1 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - FRAMEWORK_SEARCH_PATHS = ( - "$(SDKROOT)/Developer/Library/Frameworks", - "$(inherited)", - ); - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - INFOPLIST_FILE = FieryCrucibleTests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = "com.franticapparatus.$(PRODUCT_NAME:rfc1034identifier)"; - PRODUCT_NAME = "$(TARGET_NAME)"; - }; - name = Debug; - }; - E53405C51A3020CF00A474C1 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - FRAMEWORK_SEARCH_PATHS = ( - "$(SDKROOT)/Developer/Library/Frameworks", - "$(inherited)", - ); - INFOPLIST_FILE = FieryCrucibleTests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = "com.franticapparatus.$(PRODUCT_NAME:rfc1034identifier)"; - PRODUCT_NAME = "$(TARGET_NAME)"; - }; - name = Release; - }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ @@ -408,15 +293,6 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - E53405C31A3020CF00A474C1 /* Build configuration list for PBXNativeTarget "FieryCrucibleTests" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - E53405C41A3020CF00A474C1 /* Debug */, - E53405C51A3020CF00A474C1 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; /* End XCConfigurationList section */ }; rootObject = E53405A11A3020CE00A474C1 /* Project object */; diff --git a/FieryCrucible.xcodeproj/xcshareddata/xcschemes/FieryCrucible.xcscheme b/FieryCrucible.xcodeproj/xcshareddata/xcschemes/FieryCrucible.xcscheme index ced405f..56f26bd 100644 --- a/FieryCrucible.xcodeproj/xcshareddata/xcschemes/FieryCrucible.xcscheme +++ b/FieryCrucible.xcodeproj/xcshareddata/xcschemes/FieryCrucible.xcscheme @@ -42,16 +42,6 @@ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" shouldUseLaunchSchemeArgsEnv = "YES"> - - - - (@noescape factory factory: () -> T, name: String = __FUNCTION__, configure: ((T) -> ())? = nil) -> T { + return shared(name, factory: factory(), configure: configure) + } + public final func shared(@autoclosure factory: () -> T, name: String = __FUNCTION__, configure: ((T) -> ())? = nil) -> T { return shared(name, factory: factory, configure: configure) } @@ -105,7 +104,11 @@ public class DependencyFactory { configure: configure ) } - + + public final func weakShared(@noescape factory factory: () -> T, name: String = __FUNCTION__, configure: ((T) -> ())? = nil) -> T { + return weakShared(name, factory: factory(), configure: configure) + } + public final func weakShared(@autoclosure factory: () -> T, name: String = __FUNCTION__, configure: ((T) -> ())? = nil) -> T { return weakShared(name, factory: factory, configure: configure) } @@ -120,7 +123,11 @@ public class DependencyFactory { configure: configure ) } - + + public final func unshared(@noescape factory factory: () -> T, name: String = __FUNCTION__, configure: ((T) -> ())? = nil) -> T { + return unshared(name, factory: factory(), configure: configure) + } + public final func unshared(@autoclosure factory: () -> T, name: String = __FUNCTION__, configure: ((T) -> ())? = nil) -> T { return unshared(name, factory: factory, configure: configure) } @@ -136,7 +143,11 @@ public class DependencyFactory { configure: configure ) } - + + public final func scoped(@noescape factory factory: () -> T, name: String = __FUNCTION__, configure: ((T) -> ())? = nil) -> T { + return scoped(name, factory: factory(), configure: configure) + } + public final func scoped(@autoclosure factory: () -> T, name: String = __FUNCTION__, configure: ((T) -> ())? = nil) -> T { return scoped(name, factory: factory, configure: configure) } diff --git a/FieryCrucible/FieryCrucible.h b/FieryCrucible/FieryCrucible.h index c0dae60..2ae0d2e 100644 --- a/FieryCrucible/FieryCrucible.h +++ b/FieryCrucible/FieryCrucible.h @@ -1,8 +1,4 @@ -// -// FieryCrucible.h -// FieryCrucible -// -// Copyright (c) 2015 Justin Kolb - http://franticapparatus.net +// Copyright (c) 2016 Justin Kolb - http://franticapparatus.net // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -21,16 +17,8 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -// #import -//! Project version number for FieryCrucible. FOUNDATION_EXPORT double FieryCrucibleVersionNumber; - -//! Project version string for FieryCrucible. FOUNDATION_EXPORT const unsigned char FieryCrucibleVersionString[]; - -// In this header, you should import all the public headers of your framework using statements like #import - - diff --git a/FieryCrucible/Info.plist b/FieryCrucible/Info.plist index fba37c1..94e2f84 100644 --- a/FieryCrucible/Info.plist +++ b/FieryCrucible/Info.plist @@ -15,11 +15,11 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.2.0 + 1.3.1 CFBundleSignature ???? CFBundleVersion - 1.2.0 + 1.3.1 NSPrincipalClass diff --git a/FieryCrucibleTests/FieryCrucibleTests.swift b/FieryCrucibleTests/FieryCrucibleTests.swift deleted file mode 100644 index e13a7b3..0000000 --- a/FieryCrucibleTests/FieryCrucibleTests.swift +++ /dev/null @@ -1,30 +0,0 @@ -// -// FieryCrucibleTests.swift -// FieryCrucible -// -// Copyright (c) 2015 Justin Kolb - http://franticapparatus.net -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// - -import UIKit -import XCTest - -class FieryCrucibleTests: XCTestCase { -} diff --git a/FieryCrucibleTests/Info.plist b/FieryCrucibleTests/Info.plist deleted file mode 100644 index ba72822..0000000 --- a/FieryCrucibleTests/Info.plist +++ /dev/null @@ -1,24 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - BNDL - CFBundleShortVersionString - 1.0 - CFBundleSignature - ???? - CFBundleVersion - 1 - - diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..df8ca32 --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2016 Justin Kolb - http://franticapparatus.net + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README.md b/README.md index 71b2e5f..6a6e870 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,9 @@ A minimalist type safe Swift dependency injector factory. Where all true instanc #### Changelog +#####Version 1.3.1 +* There is a new form of each method where you are now able to set properties directly after initialization has occured in the factory parameter, this allows you to setup the object (with non-circular dependencies) before the object becomes available to other objects. See the updated example below. + #####Version 1.3.0 * Added support for Swift 2 @@ -38,18 +41,25 @@ You can either copy the source into your project, or setup a git submodle of thi import FieryCrucible import UIKit - class CustomFactory : DependencyFactory { + class CustomFactory : DependencyFactory { func application() -> CustomApplication { return shared(CustomApplication()) { instance in instance.factory = self } } - func mainWindow() -> UIWindow { - return shared(UIWindow(frame: UIScreen.mainScreen().bounds)) { instance in - instance.rootViewController = self.rootViewController() - } - } + func mainWindow() -> UIWindow { + return shared( + factory: { + let instance = UIWindow(frame: UIScreen.mainScreen().bounds) + instance.backgroundColor = UIColor.whiteColor() + return instance + }, + configure: { instance in + instance.rootViewController = self.rootViewController() + } + ) + } func rootViewController() -> UIViewController { return scoped(UITabBarController()) { instance in