diff --git a/Prephirences.podspec b/Prephirences.podspec index 7620e47..5349fe2 100644 --- a/Prephirences.podspec +++ b/Prephirences.podspec @@ -2,7 +2,7 @@ Pod::Spec.new do |s| # ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # s.name = "Prephirences" - s.version = "1.2.0" + s.version = "1.2.1" s.summary = "A Swift library to manage preferences" s.description = <<-DESC Prephirences is a Swift library that provides useful protocols and methods to manage preferences. @@ -21,7 +21,7 @@ Pod::Spec.new do |s| s.osx.deployment_target = "10.9" # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # - s.source = { :git => "https://github.com/phimage/Prephirences.git", :tag => '1.2.0' } + s.source = { :git => "https://github.com/phimage/Prephirences.git", :tag => s.version } # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # diff --git a/Prephirences/Preference.swift b/Prephirences/Preference.swift index 59a4962..6cf8d6f 100644 --- a/Prephirences/Preference.swift +++ b/Prephirences/Preference.swift @@ -87,16 +87,36 @@ public func ?= (preference: MutablePreference, @autoclosure expr: () -> T) } } +// MARK: Pattern match +public func ~= (value: T, preference: Preference) -> Bool { + if let pv = preference.value { + return pv ~= value + } + return false +} +public func ~= (value: I.Bound, preference: Preference) -> Bool { + if let pv = preference.value { + return pv ~= value + } + return false +} +public func ~= (value: Range, preference: Preference) -> Bool { + if let pv = preference.value { + return value ~= pv + } + return false +} + // MARK: Equatable -func == (left: Preference, right: Preference) -> Bool { +public func == (left: Preference, right: Preference) -> Bool { return left.value == right.value } -func != (left: Preference, right: Preference) -> Bool { +public func != (left: Preference, right: Preference) -> Bool { return !(left == right) } // MARK: Comparable -func < (left: Preference, right: Preference) -> Bool { +public func < (left: Preference, right: Preference) -> Bool { return left.value < right.value } diff --git a/PrephirencesiOSTests/PrephirencesiOSTests.swift b/PrephirencesiOSTests/PrephirencesiOSTests.swift index 0fa65e2..54899cf 100644 --- a/PrephirencesiOSTests/PrephirencesiOSTests.swift +++ b/PrephirencesiOSTests/PrephirencesiOSTests.swift @@ -158,6 +158,19 @@ class PrephirencesiOSTests: XCTestCase { intPref /= 3 XCTAssert(intPref.value! == 10) + switch(intPref) { + case 1: XCTFail("not equal in switch") + case 10: println("ok") + default: XCTFail("not equal in switch") + } + + switch(intPref) { + case 0...9: XCTFail("not equal in switch") + case 11...999: XCTFail("not equal in switch") + case 9...11: println("ok") + default: XCTFail("not equal in switch") + } + var boolPref: MutablePreference = Prephirences.preferenceForKey("bool", userDefaults) boolPref.value = nil @@ -190,6 +203,20 @@ class PrephirencesiOSTests: XCTestCase { XCTAssert(boolPref.value! == false) boolPref ||= true XCTAssert(boolPref.value! == true) + + switch(boolPref) { + case true: println("ok") + case false: XCTFail("not true") + default: XCTFail("nil") + } + + var stringPref: MutablePreference = Prephirences.preferenceForKey("string", userDefaults) + stringPref.value = "pref" + + stringPref += "erence" + XCTAssert(stringPref.value! == "preference") + + } } \ No newline at end of file diff --git a/README.md b/README.md index 433a324..1d834c5 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,12 @@ intPref *= 20 intPref %= 7 intPref /= 3 +switch(intPref) { + case 1: println("one") + case 2...10: println("not one or zero but...") + default: println("unkwown") +} + var boolPref: MutablePreference = Prephirences.preferenceForKey("boolKey", aPrefs) boolPref &= false