diff --git a/ABKit.xcodeproj/project.pbxproj b/ABKit.xcodeproj/project.pbxproj index 1c4e54f..8010402 100644 --- a/ABKit.xcodeproj/project.pbxproj +++ b/ABKit.xcodeproj/project.pbxproj @@ -7,7 +7,6 @@ objects = { /* Begin PBXBuildFile section */ - 38EF8B652AF26F2465387A33 /* Pods_ABKitTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 22E564495A2765E422B3B15D /* Pods_ABKitTests.framework */; }; 3D10CF2B1C6DA4E1002A2016 /* ABKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 3D10CF2A1C6DA4E1002A2016 /* ABKit.h */; settings = {ATTRIBUTES = (Public, ); }; }; 3D10CF321C6DA4E1002A2016 /* ABKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3D10CF271C6DA4E1002A2016 /* ABKit.framework */; }; 3D2CCB0C1C7FDDC200152924 /* ConditionalTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D2CCB0B1C7FDDC200152924 /* ConditionalTest.swift */; }; @@ -22,6 +21,7 @@ 53D5F9B01C6DCE64004E832B /* VersionWeightSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53D5F9AF1C6DCE64004E832B /* VersionWeightSpec.swift */; }; 53D5F9B21C6DD149004E832B /* NSUserDefaults+RandomNumberRepositorySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53D5F9B11C6DD149004E832B /* NSUserDefaults+RandomNumberRepositorySpec.swift */; }; 53DC27A11C6DAED20040005E /* SplitTestSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53DC27A01C6DAED20040005E /* SplitTestSpec.swift */; }; + 7E948B280736EF698CD13CCB /* Pods_ABKitTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F3979C2DB7D7D34621F17940 /* Pods_ABKitTests.framework */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -35,8 +35,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 1030AAA5A25025EFD4FDF524 /* Pods-ABKitTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ABKitTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ABKitTests/Pods-ABKitTests.debug.xcconfig"; sourceTree = ""; }; - 22E564495A2765E422B3B15D /* Pods_ABKitTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_ABKitTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 18196A0E260D580069CCD489 /* Pods-ABKitTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ABKitTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ABKitTests/Pods-ABKitTests.debug.xcconfig"; sourceTree = ""; }; 3D10CF271C6DA4E1002A2016 /* ABKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ABKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 3D10CF2A1C6DA4E1002A2016 /* ABKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ABKit.h; sourceTree = ""; }; 3D10CF2C1C6DA4E1002A2016 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -51,10 +50,11 @@ 3DD4E6661C6DAA190089473B /* Version.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Version.swift; sourceTree = ""; }; 3DD4E66A1C6DAD410089473B /* RandomNumberRepository.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RandomNumberRepository.swift; sourceTree = ""; }; 3DD4E66C1C6DAE4A0089473B /* NSUserDefaults+RandomNumberRepository.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSUserDefaults+RandomNumberRepository.swift"; sourceTree = ""; }; - 4BFA0C4A40C2D2B016305DBC /* Pods-ABKitTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ABKitTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-ABKitTests/Pods-ABKitTests.release.xcconfig"; sourceTree = ""; }; 53D5F9AF1C6DCE64004E832B /* VersionWeightSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VersionWeightSpec.swift; sourceTree = ""; }; 53D5F9B11C6DD149004E832B /* NSUserDefaults+RandomNumberRepositorySpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSUserDefaults+RandomNumberRepositorySpec.swift"; sourceTree = ""; }; 53DC27A01C6DAED20040005E /* SplitTestSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SplitTestSpec.swift; sourceTree = ""; }; + C7D03148CE2B5E23D4B30AE2 /* Pods-ABKitTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ABKitTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-ABKitTests/Pods-ABKitTests.release.xcconfig"; sourceTree = ""; }; + F3979C2DB7D7D34621F17940 /* Pods_ABKitTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_ABKitTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -70,7 +70,7 @@ buildActionMask = 2147483647; files = ( 3D10CF321C6DA4E1002A2016 /* ABKit.framework in Frameworks */, - 38EF8B652AF26F2465387A33 /* Pods_ABKitTests.framework in Frameworks */, + 7E948B280736EF698CD13CCB /* Pods_ABKitTests.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -83,8 +83,8 @@ 3D10CF291C6DA4E1002A2016 /* ABKit */, 3D10CF351C6DA4E1002A2016 /* ABKitTests */, 3D10CF281C6DA4E1002A2016 /* Products */, - B065F1B0026A1DD49EE95394 /* Pods */, - 4032D80C528A3D639DC536D5 /* Frameworks */, + 4583AB5654FC456C194996E1 /* Pods */, + 3FA80E33E9AFF67590B73946 /* Frameworks */, ); sourceTree = ""; }; @@ -134,19 +134,19 @@ path = Codes; sourceTree = ""; }; - 4032D80C528A3D639DC536D5 /* Frameworks */ = { + 3FA80E33E9AFF67590B73946 /* Frameworks */ = { isa = PBXGroup; children = ( - 22E564495A2765E422B3B15D /* Pods_ABKitTests.framework */, + F3979C2DB7D7D34621F17940 /* Pods_ABKitTests.framework */, ); name = Frameworks; sourceTree = ""; }; - B065F1B0026A1DD49EE95394 /* Pods */ = { + 4583AB5654FC456C194996E1 /* Pods */ = { isa = PBXGroup; children = ( - 1030AAA5A25025EFD4FDF524 /* Pods-ABKitTests.debug.xcconfig */, - 4BFA0C4A40C2D2B016305DBC /* Pods-ABKitTests.release.xcconfig */, + 18196A0E260D580069CCD489 /* Pods-ABKitTests.debug.xcconfig */, + C7D03148CE2B5E23D4B30AE2 /* Pods-ABKitTests.release.xcconfig */, ); name = Pods; sourceTree = ""; @@ -187,12 +187,12 @@ isa = PBXNativeTarget; buildConfigurationList = 3D10CF3E1C6DA4E1002A2016 /* Build configuration list for PBXNativeTarget "ABKitTests" */; buildPhases = ( - E25764AB338FE1DB92D00F7C /* Check Pods Manifest.lock */, + 6A46FE3F4C9ED35383BB3895 /* [CP] Check Pods Manifest.lock */, 3D10CF2D1C6DA4E1002A2016 /* Sources */, 3D10CF2E1C6DA4E1002A2016 /* Frameworks */, 3D10CF2F1C6DA4E1002A2016 /* Resources */, - 046228D421FEC92C198AC274 /* Embed Pods Frameworks */, - B0D2480D98990ACCDC21F66F /* Copy Pods Resources */, + 1A134F79F86A0D4AEC6C2F45 /* [CP] Embed Pods Frameworks */, + E73E8F30CF30644015F89BCD /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -211,14 +211,16 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 0720; + LastUpgradeCheck = 0830; ORGANIZATIONNAME = "Recruit Marketing Partners Co.,Ltd."; TargetAttributes = { 3D10CF261C6DA4E1002A2016 = { CreatedOnToolsVersion = 7.2; + LastSwiftMigration = 0830; }; 3D10CF301C6DA4E1002A2016 = { CreatedOnToolsVersion = 7.2; + LastSwiftMigration = 0830; }; }; }; @@ -258,14 +260,14 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 046228D421FEC92C198AC274 /* Embed Pods Frameworks */ = { + 1A134F79F86A0D4AEC6C2F45 /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); - name = "Embed Pods Frameworks"; + name = "[CP] Embed Pods Frameworks"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; @@ -273,34 +275,34 @@ shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-ABKitTests/Pods-ABKitTests-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; - B0D2480D98990ACCDC21F66F /* Copy Pods Resources */ = { + 6A46FE3F4C9ED35383BB3895 /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); - name = "Copy Pods Resources"; + name = "[CP] Check Pods Manifest.lock"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-ABKitTests/Pods-ABKitTests-resources.sh\"\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; showEnvVarsInLog = 0; }; - E25764AB338FE1DB92D00F7C /* Check Pods Manifest.lock */ = { + E73E8F30CF30644015F89BCD /* [CP] Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); - name = "Check Pods Manifest.lock"; + name = "[CP] Copy Pods Resources"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-ABKitTests/Pods-ABKitTests-resources.sh\"\n"; showEnvVarsInLog = 0; }; /* End PBXShellScriptBuildPhase section */ @@ -356,8 +358,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -404,8 +408,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -425,6 +431,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 9.2; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -436,6 +443,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -447,6 +455,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -454,6 +463,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -464,28 +474,33 @@ PRODUCT_BUNDLE_IDENTIFIER = "jp.co.recruit-mp.ABKit"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; }; name = Release; }; 3D10CF3F1C6DA4E1002A2016 /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 1030AAA5A25025EFD4FDF524 /* Pods-ABKitTests.debug.xcconfig */; + baseConfigurationReference = 18196A0E260D580069CCD489 /* Pods-ABKitTests.debug.xcconfig */; buildSettings = { + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = ABKitTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "jp.co.recruit-mp.ABKitTests"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Debug; }; 3D10CF401C6DA4E1002A2016 /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 4BFA0C4A40C2D2B016305DBC /* Pods-ABKitTests.release.xcconfig */; + baseConfigurationReference = C7D03148CE2B5E23D4B30AE2 /* Pods-ABKitTests.release.xcconfig */; buildSettings = { + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = ABKitTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "jp.co.recruit-mp.ABKitTests"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/ABKit.xcodeproj/xcshareddata/xcschemes/ABKit.xcscheme b/ABKit.xcodeproj/xcshareddata/xcschemes/ABKit.xcscheme index df323b3..cab6f6e 100644 --- a/ABKit.xcodeproj/xcshareddata/xcschemes/ABKit.xcscheme +++ b/ABKit.xcodeproj/xcshareddata/xcschemes/ABKit.xcscheme @@ -1,6 +1,6 @@ { - public let name: String - public let defaultVersion: Version +open class ConditionalTest { + open let name: String + open let defaultVersion: Version - private var versions: [ConditionalVersion] = [] + fileprivate var versions: [ConditionalVersion] = [] public init(name: String, defaultVersion: Version) { self.name = name self.defaultVersion = defaultVersion } - public func addVersion(version: Version, condition: (T) -> Bool) { + open func addVersion(_ version: Version, condition: @escaping (T) -> Bool) { let conditionalVersion = ConditionalVersion(name: version.name, behavior: version.behavior, condition: condition) versions.append(conditionalVersion) } - public func run(value: T) { + open func run(_ value: T) { var isRun = false for version in versions { if version.condition(value) { diff --git a/ABKit/Codes/ConditionalVersion.swift b/ABKit/Codes/ConditionalVersion.swift index 9dc07ba..500b648 100644 --- a/ABKit/Codes/ConditionalVersion.swift +++ b/ABKit/Codes/ConditionalVersion.swift @@ -7,9 +7,9 @@ // class ConditionalVersion: Version { - let condition: T -> Bool + let condition: (T) -> Bool - init(name: String, behavior: Version -> Void, condition: T -> Bool) { + init(name: String, behavior: @escaping (Version) -> Void, condition: @escaping (T) -> Bool) { self.condition = condition super.init(name: name, behavior: behavior) } diff --git a/ABKit/Codes/NSUserDefaults+RandomNumberRepository.swift b/ABKit/Codes/NSUserDefaults+RandomNumberRepository.swift index ec8552b..99b5601 100644 --- a/ABKit/Codes/NSUserDefaults+RandomNumberRepository.swift +++ b/ABKit/Codes/NSUserDefaults+RandomNumberRepository.swift @@ -6,21 +6,21 @@ // Copyright © 2016 Recruit Marketing Partners Co.,Ltd. All rights reserved. // -extension NSUserDefaults: RandomNumberRepository { - public func ab_getRandomNumberWithKey(key: String) -> Int { - var randomNumber = integerForKey(key) +extension UserDefaults: RandomNumberRepository { + public func ab_getRandomNumberWithKey(_ key: String) -> Int { + var randomNumber = integer(forKey: key) if randomNumber == 0 { randomNumber = generateRandomNumber() - setInteger(randomNumber, forKey: key) + set(randomNumber, forKey: key) } return randomNumber } - public func ab_setRandomNumber(randomNumber: Int, key: String) { - setInteger(randomNumber, forKey: key) + public func ab_setRandomNumber(_ randomNumber: Int, key: String) { + set(randomNumber, forKey: key) } - public func ab_deleteRandomNumberWithKey(key: String) { - removeObjectForKey(key) + public func ab_deleteRandomNumberWithKey(_ key: String) { + removeObject(forKey: key) } } diff --git a/ABKit/Codes/RandomNumberRepository.swift b/ABKit/Codes/RandomNumberRepository.swift index 41642fe..ead6bed 100644 --- a/ABKit/Codes/RandomNumberRepository.swift +++ b/ABKit/Codes/RandomNumberRepository.swift @@ -9,9 +9,9 @@ import Foundation public protocol RandomNumberRepository { - func ab_getRandomNumberWithKey(key: String) -> Int - func ab_setRandomNumber(randomNumber: Int, key: String) - func ab_deleteRandomNumberWithKey(key: String) + func ab_getRandomNumberWithKey(_ key: String) -> Int + func ab_setRandomNumber(_ randomNumber: Int, key: String) + func ab_deleteRandomNumberWithKey(_ key: String) } extension RandomNumberRepository { diff --git a/ABKit/Codes/SplitTest.swift b/ABKit/Codes/SplitTest.swift index cbb57ef..1295cdc 100644 --- a/ABKit/Codes/SplitTest.swift +++ b/ABKit/Codes/SplitTest.swift @@ -8,12 +8,12 @@ import Foundation -public class SplitTest { +open class SplitTest { var versionWeights: [VersionWeight] = [] - private let name: String - private let defaultVersion: Version - private let randomNumberRepository: RandomNumberRepository + fileprivate let name: String + fileprivate let defaultVersion: Version + fileprivate let randomNumberRepository: RandomNumberRepository public init(name: String, defaultVersion: Version, randomNumberRepository: RandomNumberRepository) { self.name = name @@ -22,16 +22,16 @@ public class SplitTest { } public convenience init(name: String, defaultVersion: Version) { - let defaultRepository = NSUserDefaults.standardUserDefaults() - self.init(name: name, defaultVersion: defaultVersion, randomNumberRepository: defaultRepository) + let defaultRepository = UserDefaults.standard + self.init(name: name, defaultVersion: defaultVersion, randomNumberRepository: defaultRepository as RandomNumberRepository) } - public func addVersion(version: Version, weight: Float) { + open func addVersion(_ version: Version, weight: Float) { let versionWeight = VersionWeight(version: version, weight: Int(weight * 100)) versionWeights.append(versionWeight) } - public func run() { + open func run() { assertExcessWeight() calculateWeightRanges() let randomNumber = randomNumberRepository.ab_getRandomNumberWithKey("ABKit-\(name)") @@ -39,31 +39,31 @@ public class SplitTest { version.behavior(version) } - public func setRandomNumber(randomNumber: Int) { + open func setRandomNumber(_ randomNumber: Int) { randomNumberRepository.ab_setRandomNumber(randomNumber, key: "ABKit-\(name)") } - public func deleteRandomNumber() { + open func deleteRandomNumber() { randomNumberRepository.ab_deleteRandomNumberWithKey("ABKit-\(name)") } - private func assertExcessWeight() { + fileprivate func assertExcessWeight() { let totalWeight = versionWeights.reduce(0) { $0 + $1.weight } assert(totalWeight <= 100, "Total weight (\(totalWeight / 100)) must be below 1.0") } - private func calculateWeightRanges() { + fileprivate func calculateWeightRanges() { var weightIndex = 0 - for (index, versionWeight) in versionWeights.enumerate() { + for (index, versionWeight) in versionWeights.enumerated() { let min = weightIndex let max = weightIndex + versionWeight.weight versionWeights[index].weightRange = min.. Version { + fileprivate func selectVersionByRandomNumber(_ randomNumber: Int) -> Version { let versions = versionWeights.filter { $0.contains(randomNumber) }.map { $0.version } return versions.first ?? defaultVersion } diff --git a/ABKit/Codes/Version.swift b/ABKit/Codes/Version.swift index 46ff4f2..623ef9e 100644 --- a/ABKit/Codes/Version.swift +++ b/ABKit/Codes/Version.swift @@ -6,11 +6,11 @@ // Copyright © 2016 Recruit Marketing Partners Co.,Ltd. All rights reserved. // -public class Version { - public let name: String - let behavior: Version -> Void +open class Version { + open let name: String + let behavior: (Version) -> Void - public init(name: String, behavior: Version -> Void) { + public init(name: String, behavior: @escaping (Version) -> Void) { self.name = name self.behavior = behavior } diff --git a/ABKit/Codes/VersionWeight.swift b/ABKit/Codes/VersionWeight.swift index d075736..2b40a16 100644 --- a/ABKit/Codes/VersionWeight.swift +++ b/ABKit/Codes/VersionWeight.swift @@ -9,14 +9,14 @@ class VersionWeight { let version: Version let weight: Int - var weightRange: Range = 0..<100 + var weightRange: CountableRange = 0..<100 init(version: Version, weight: Int) { self.version = version self.weight = weight } - func contains(number: Int) -> Bool { + func contains(_ number: Int) -> Bool { return weightRange.contains(number) } } diff --git a/ABKitTests/SplitTestSpec.swift b/ABKitTests/SplitTestSpec.swift index 7317734..a09e9fc 100644 --- a/ABKitTests/SplitTestSpec.swift +++ b/ABKitTests/SplitTestSpec.swift @@ -76,13 +76,13 @@ class SplitTestSpec: QuickSpec { } class TestRandomNumberRepository: RandomNumberRepository { - func ab_getRandomNumberWithKey(key: String) -> Int { + func ab_getRandomNumberWithKey(_ key: String) -> Int { return 1 } - func ab_setRandomNumber(randomNumber: Int, key: String) { + func ab_setRandomNumber(_ randomNumber: Int, key: String) { } - func ab_deleteRandomNumberWithKey(key: String) { + func ab_deleteRandomNumberWithKey(_ key: String) { } } diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index 6f05105..5567af3 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -7,7 +7,7 @@ objects = { /* Begin PBXBuildFile section */ - 587BC58AC4BD53632ED0A347 /* Pods.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 25CA89E3BEDF95D2B34E9DB7 /* Pods.framework */; }; + 60F082D20201D4F6B044CD1C /* Pods_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2A7990B8C14641A976B8E79B /* Pods_Example.framework */; }; B633F0FA1C7FDF5F0094A3CA /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B633F0F91C7FDF5F0094A3CA /* AppDelegate.swift */; }; B633F0FF1C7FDF5F0094A3CA /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B633F0FD1C7FDF5F0094A3CA /* Main.storyboard */; }; B633F1011C7FDF5F0094A3CA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B633F1001C7FDF5F0094A3CA /* Assets.xcassets */; }; @@ -53,7 +53,7 @@ /* Begin PBXFileReference section */ 25CA89E3BEDF95D2B34E9DB7 /* Pods.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 45BE5733F0D406D2C2B866DB /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = ""; }; + 2A7990B8C14641A976B8E79B /* Pods_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; }; B633F0F61C7FDF5F0094A3CA /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; B633F0F91C7FDF5F0094A3CA /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; B633F0FE1C7FDF5F0094A3CA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; @@ -97,7 +97,8 @@ B650912C1C8003AC00DBA632 /* ImageCollectionViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageCollectionViewController.swift; sourceTree = ""; }; B650912E1C8003B900DBA632 /* ImageTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageTableViewController.swift; sourceTree = ""; }; B65091501C80058100DBA632 /* ImageTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageTableViewCell.swift; sourceTree = ""; }; - BF15F782556E590CC77D0D32 /* Pods.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.release.xcconfig; path = "Pods/Target Support Files/Pods/Pods.release.xcconfig"; sourceTree = ""; }; + C13BE3FCF8733F415679FF3F /* Pods-Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-Example/Pods-Example.release.xcconfig"; sourceTree = ""; }; + C94899E73CD7A16A90F75A95 /* Pods-Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Example/Pods-Example.debug.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -105,17 +106,27 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 587BC58AC4BD53632ED0A347 /* Pods.framework in Frameworks */, + 60F082D20201D4F6B044CD1C /* Pods_Example.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 274CBEBF93EA9B8B89B0245C /* Pods */ = { + isa = PBXGroup; + children = ( + C94899E73CD7A16A90F75A95 /* Pods-Example.debug.xcconfig */, + C13BE3FCF8733F415679FF3F /* Pods-Example.release.xcconfig */, + ); + name = Pods; + sourceTree = ""; + }; 27B5C7E3241EE2F4A786FCB2 /* Frameworks */ = { isa = PBXGroup; children = ( 25CA89E3BEDF95D2B34E9DB7 /* Pods.framework */, + 2A7990B8C14641A976B8E79B /* Pods_Example.framework */, ); name = Frameworks; sourceTree = ""; @@ -125,8 +136,8 @@ children = ( B633F0F81C7FDF5F0094A3CA /* Example */, B633F0F71C7FDF5F0094A3CA /* Products */, - C54270FEEE46C705AD2E8492 /* Pods */, 27B5C7E3241EE2F4A786FCB2 /* Frameworks */, + 274CBEBF93EA9B8B89B0245C /* Pods */, ); sourceTree = ""; }; @@ -211,15 +222,6 @@ path = S; sourceTree = ""; }; - C54270FEEE46C705AD2E8492 /* Pods */ = { - isa = PBXGroup; - children = ( - 45BE5733F0D406D2C2B866DB /* Pods.debug.xcconfig */, - BF15F782556E590CC77D0D32 /* Pods.release.xcconfig */, - ); - name = Pods; - sourceTree = ""; - }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -227,12 +229,12 @@ isa = PBXNativeTarget; buildConfigurationList = B633F1081C7FDF5F0094A3CA /* Build configuration list for PBXNativeTarget "Example" */; buildPhases = ( - 26106969B2A7864BEC294239 /* Check Pods Manifest.lock */, + F466949EFEE7D9FE0F8F2223 /* [CP] Check Pods Manifest.lock */, B633F0F21C7FDF5F0094A3CA /* Sources */, B633F0F31C7FDF5F0094A3CA /* Frameworks */, B633F0F41C7FDF5F0094A3CA /* Resources */, - 32E0BFEF5A54DADF5F870B47 /* Embed Pods Frameworks */, - A9E16FAE4DE35F482682A17C /* Copy Pods Resources */, + CB78AF8C7F0DC1DB5B40A0ED /* [CP] Embed Pods Frameworks */, + FFE9090E165D6853D34DE633 /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -250,11 +252,12 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 0720; + LastUpgradeCheck = 0830; ORGANIZATIONNAME = "Recruit Marketing Partners"; TargetAttributes = { B633F0F51C7FDF5F0094A3CA = { CreatedOnToolsVersion = 7.2.1; + LastSwiftMigration = 0830; }; }; }; @@ -322,49 +325,55 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 26106969B2A7864BEC294239 /* Check Pods Manifest.lock */ = { + CB78AF8C7F0DC1DB5B40A0ED /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( + "${SRCROOT}/Pods/Target Support Files/Pods-Example/Pods-Example-frameworks.sh", + "${BUILT_PRODUCTS_DIR}/ABKit/ABKit.framework", ); - name = "Check Pods Manifest.lock"; + name = "[CP] Embed Pods Frameworks"; outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/ABKit.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Example/Pods-Example-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; - 32E0BFEF5A54DADF5F870B47 /* Embed Pods Frameworks */ = { + F466949EFEE7D9FE0F8F2223 /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", ); - name = "Embed Pods Frameworks"; + name = "[CP] Check Pods Manifest.lock"; outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-Example-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods/Pods-frameworks.sh\"\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; - A9E16FAE4DE35F482682A17C /* Copy Pods Resources */ = { + FFE9090E165D6853D34DE633 /* [CP] Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); - name = "Copy Pods Resources"; + name = "[CP] Copy Pods Resources"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods/Pods-resources.sh\"\n"; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Example/Pods-Example-resources.sh\"\n"; showEnvVarsInLog = 0; }; /* End PBXShellScriptBuildPhase section */ @@ -418,8 +427,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -462,8 +473,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -482,31 +495,34 @@ IPHONEOS_DEPLOYMENT_TARGET = 9.2; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; VALIDATE_PRODUCT = YES; }; name = Release; }; B633F1091C7FDF5F0094A3CA /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 45BE5733F0D406D2C2B866DB /* Pods.debug.xcconfig */; + baseConfigurationReference = C94899E73CD7A16A90F75A95 /* Pods-Example.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = Example/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = jp.co.recruit.Example; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Debug; }; B633F10A1C7FDF5F0094A3CA /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = BF15F782556E590CC77D0D32 /* Pods.release.xcconfig */; + baseConfigurationReference = C13BE3FCF8733F415679FF3F /* Pods-Example.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = Example/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = jp.co.recruit.Example; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/Example/Example/AppDelegate.swift b/Example/Example/AppDelegate.swift index 06edea9..3d85a8a 100644 --- a/Example/Example/AppDelegate.swift +++ b/Example/Example/AppDelegate.swift @@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. return true } - func applicationWillResignActive(application: UIApplication) { + func applicationWillResignActive(_ application: UIApplication) { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. } - func applicationDidEnterBackground(application: UIApplication) { + func applicationDidEnterBackground(_ application: UIApplication) { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } - func applicationWillEnterForeground(application: UIApplication) { + func applicationWillEnterForeground(_ application: UIApplication) { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. } - func applicationDidBecomeActive(application: UIApplication) { + func applicationDidBecomeActive(_ application: UIApplication) { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } - func applicationWillTerminate(application: UIApplication) { + func applicationWillTerminate(_ application: UIApplication) { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } diff --git a/Example/Example/Base.lproj/Main.storyboard b/Example/Example/Base.lproj/Main.storyboard index a645592..b981214 100644 --- a/Example/Example/Base.lproj/Main.storyboard +++ b/Example/Example/Base.lproj/Main.storyboard @@ -1,10 +1,14 @@ - - + + + + + - + + @@ -14,56 +18,56 @@ - + - + - + - + - + - + - + @@ -95,25 +99,25 @@ - + - + - + @@ -140,22 +144,22 @@ - + - + @@ -190,7 +194,7 @@ - + @@ -207,7 +211,7 @@ - + @@ -218,16 +222,15 @@ - @@ -252,13 +255,12 @@ - + - @@ -269,16 +271,16 @@ - + - + - + @@ -295,12 +297,12 @@ @@ -310,7 +312,6 @@ - diff --git a/Example/Example/ImageCollectionViewController.swift b/Example/Example/ImageCollectionViewController.swift index 531871c..6a1d5e1 100644 --- a/Example/Example/ImageCollectionViewController.swift +++ b/Example/Example/ImageCollectionViewController.swift @@ -9,19 +9,19 @@ import UIKit class ImageCollectionViewController: UICollectionViewController { - private struct Constants { + fileprivate struct Constants { static let cellMargin = CGFloat(5.0) static let numberOfColumns = 2 } - private var imageNames: [String]? + fileprivate var imageNames: [String]? override func viewDidLoad() { super.viewDidLoad() setupData() } - private func setupData() { + fileprivate func setupData() { // We prepared 16 images for example var imageNames = [String]() for i in 1...16 { @@ -31,16 +31,16 @@ class ImageCollectionViewController: UICollectionViewController { self.imageNames = imageNames } - override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int { + override func numberOfSections(in collectionView: UICollectionView) -> Int { return 1 } - override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return self.imageNames?.count ?? 0 } - override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { - let cell = collectionView.dequeueReusableCellWithReuseIdentifier("ImageCell", forIndexPath: indexPath) + override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ImageCell", for: indexPath) if let imageCell = cell as? ImageCollectionViewCell, let imageName = imageNames?[indexPath.row] { imageCell.imageName = imageName @@ -51,14 +51,14 @@ class ImageCollectionViewController: UICollectionViewController { } extension ImageCollectionViewController: UICollectionViewDelegateFlowLayout { - func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize { + func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { - let width = CGRectGetWidth(collectionView.frame) / CGFloat(Constants.numberOfColumns) - (Constants.cellMargin * 2) + let width = collectionView.frame.width / CGFloat(Constants.numberOfColumns) - (Constants.cellMargin * 2) - return CGSizeMake(width, width) + return CGSize(width: width, height: width) } - func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAtIndex section: Int) -> UIEdgeInsets { + func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets { return UIEdgeInsetsMake(0, Constants.cellMargin, Constants.cellMargin, Constants.cellMargin) } -} \ No newline at end of file +} diff --git a/Example/Example/ImageTableViewController.swift b/Example/Example/ImageTableViewController.swift index dceb3bd..7701636 100644 --- a/Example/Example/ImageTableViewController.swift +++ b/Example/Example/ImageTableViewController.swift @@ -13,7 +13,7 @@ class ImageTableViewController: UITableViewController { case Left, Right } - private var imageNames: [String]? + fileprivate var imageNames: [String]? var cellType = CellType.Left override func viewDidLoad() { @@ -23,7 +23,7 @@ class ImageTableViewController: UITableViewController { setupData() } - private func setupData() { + fileprivate func setupData() { // We prepared 16 images for example var imageNames = [String]() for i in 1...16 { @@ -33,16 +33,16 @@ class ImageTableViewController: UITableViewController { self.imageNames = imageNames } - override func numberOfSectionsInTableView(tableView: UITableView) -> Int { + override func numberOfSections(in tableView: UITableView) -> Int { return 1 } - override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return imageNames?.count ?? 0 } - override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { - let cell = tableView.dequeueReusableCellWithIdentifier(cellType.rawValue, forIndexPath: indexPath) + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(withIdentifier: cellType.rawValue, for: indexPath) if let imageCell = cell as? ImageTableViewCell, let imageName = imageNames?[indexPath.row] { imageCell.imageName = imageName diff --git a/Example/Example/RootViewController.swift b/Example/Example/RootViewController.swift index 89e4399..b3806a9 100644 --- a/Example/Example/RootViewController.swift +++ b/Example/Example/RootViewController.swift @@ -10,7 +10,7 @@ import UIKit import ABKit class RootViewController: UITableViewController { - override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { + override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { switch indexPath.row { case 0: runABTest() @@ -22,8 +22,8 @@ class RootViewController: UITableViewController { } } - override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { - switch segue.destinationViewController { + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { + switch segue.destination { case let viewController as ImageTableViewController: if segue.identifier == "showRightImageTableView" { viewController.cellType = .Right @@ -34,57 +34,66 @@ class RootViewController: UITableViewController { } } - private func runABTest() { + fileprivate func runABTest() { let defaultVersion = Version(name: "A") { version in print("Pattern \(version.name)") - self.performSegueWithIdentifier("showImageTableView", sender: self) + self.performSegue(withIdentifier: "showImageTableView", sender: self) } let test = SplitTest(name: "Sample A/B test", defaultVersion: defaultVersion) let b = Version(name: "B") { version in print("Pattern \(version.name)") - self.performSegueWithIdentifier("showImageCollectionView", sender: self) + self.performSegue(withIdentifier: "showImageCollectionView", sender: self) } test.addVersion(b, weight: 0.5) + test.deleteRandomNumber() test.run() } - private func runWeightedProbabilitiesSplitTest() { + fileprivate func runWeightedProbabilitiesSplitTest() { let defaultVersion = Version(name: "A") { version in print("Pattern \(version.name)") - self.performSegueWithIdentifier("showImageTableView", sender: self) + // self.performSegue(withIdentifier: "showImageTableView", sender: self) } let test = SplitTest(name: "Sample Split test", defaultVersion: defaultVersion) let b = Version(name: "B") { version in print("Pattern \(version.name)") - self.performSegueWithIdentifier("showImageCollectionView", sender: self) + // self.performSegue(withIdentifier: "showImageCollectionView", sender: self) } test.addVersion(b, weight: 0.2) let c = Version(name: "C") { version in print("Pattern \(version.name)") - self.performSegueWithIdentifier("showRightImageTableView", sender: self) + // self.performSegue(withIdentifier: "showRightImageTableView", sender: self) } - test.addVersion(c, weight: 0.3) + + let d = Version(name: "D") { version in + print("Pattern \(version.name)") + // self.performSegue(withIdentifier: "showRightImageTableView", sender: self) + } + + test.addVersion(c, weight: 0.2) + test.addVersion(d, weight: 0.2) + test.deleteRandomNumber() test.run() } - private func runConditionalTest() { + fileprivate func runConditionalTest() { let defaultVersion = Version(name: "A") { version in print("Pattern \(version.name)") - self.performSegueWithIdentifier("showImageTableView", sender: self) + self.performSegue(withIdentifier: "showImageTableView", sender: self) } let test = ConditionalTest(name: "Sample conditional test", defaultVersion: defaultVersion) let b = Version(name: "B") { version in print("Pattern \(version.name)") - self.performSegueWithIdentifier("showImageCollectionView", sender: self) + self.performSegue(withIdentifier: "showImageCollectionView", sender: self) } test.addVersion(b) { age in age < 20 } diff --git a/Example/Podfile b/Example/Podfile index eb65b32..e8778cd 100644 --- a/Example/Podfile +++ b/Example/Podfile @@ -4,4 +4,6 @@ use_frameworks! platform :ios, '9.2' -pod 'ABKit', path: '../' +target "Example" do + pod 'ABKit', :path => '../' +end diff --git a/Example/Podfile.lock b/Example/Podfile.lock index bd71e41..a494edc 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -6,9 +6,11 @@ DEPENDENCIES: EXTERNAL SOURCES: ABKit: - :path: "../" + :path: ../ SPEC CHECKSUMS: - ABKit: 0e239bd8adc0e1657e75c3c9d71cb2359eaed252 + ABKit: b8f433a335d03fe643f02b8c5196955fd3ebc642 -COCOAPODS: 0.39.0 +PODFILE CHECKSUM: 16c9f5eefcde63eaea90532a60e3feccae6702bf + +COCOAPODS: 1.3.1 diff --git a/Podfile.lock b/Podfile.lock index 2a27676..236b560 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,6 +1,6 @@ PODS: - Nimble (3.0.0) - - Quick (0.9.1) + - Quick (0.9.3) DEPENDENCIES: - Nimble (= 3.0.0) @@ -8,6 +8,8 @@ DEPENDENCIES: SPEC CHECKSUMS: Nimble: 4c353d43735b38b545cbb4cb91504588eb5de926 - Quick: a5221fc21788b6aeda934805e68b061839bc3165 + Quick: 13a2a2b19a5d8e3ed4fd0c36ee46597fd77ebf71 -COCOAPODS: 0.39.0 +PODFILE CHECKSUM: e521f47fdbe66681a7c6541c2f57f35d6a7088a2 + +COCOAPODS: 1.3.0.beta.1