Skip to content

Releases: phimage/Prephirences

3.0.0

16 Sep 13:26
Compare
Choose a tag to compare

Update to swift 3 syntax
as an example :

func objectForKey(_ key: String) -> AnyObject?` 

become

func object(forKey key: String) -> Any?

2.2.1

27 Jul 15:25
Compare
Choose a tag to compare
  • some utility functions to specify a default value when the stored value match a condition
 public var intValueMin10: MutablePreference<Int> {
   get {
     return userDefaults.preferenceForKey("intKey")
           .whenNil(use: 100)
          .ensure(when: lessThan100, use: 100)
  }
 set {..}
}
  • and... new protocol PreferenceTransformation : Before storing or accessing the value, transformation could be applied. This allow to archive, to change type, return default value if nil and many more.
userDefaults["aKey", myTransformation] = myObject

⚠️ TransformationKey implement this protocol. transfomationattribute of MutablePreference has type changed.
If you use before aPref.transformation = .Archive. Now you must use aPref.transformation = TransformationKey.Archive or aPref.transformationKey = Transformation.Archive

  • Utility functions for RawRepresentable objects

    • get an RawRepresentableobject with rawRepresentableForKey and set with setRawValue
    • For RawRepresentable objects like enum you can use the computed attribute preferenceTransformation as transformation
    enum PrefEnum: String { case One, Two, Three}
    var pref: MutablePreference<PrefEnum> = preferences <| "enumKey"
    pref.transformation = PrefEnum.preferenceTransformation
    pref.value = PrefEnum.Two

2.2.0

27 Jul 15:29
Compare
Choose a tag to compare

swift 2.2 (fix warning)

2.0.8

27 Jul 15:28
Compare
Choose a tag to compare

NSCoder implement MutablePreferencesType

 init?(coder decoder: NSCoder) {
   self.init()
   self.intVar = decoder["intVarKey"] as? Int ?? 0
   // or self.intVar = decoder.integerForKey("intVar")
   self.stringVar = decoder["stringVarKey"] as? String ?? ""
 }

 func encodeWithCoder(coder: NSCoder) {
   coder["intVarKey"] = self.intVar
   coder["stringVarKey"] = self.stringVar
 }

2.0.5

16 Dec 16:22
Compare
Choose a tag to compare

Allow to adapt a collection to PreferencesType

  • using two closures, one to get key, the other to get the value from the collection element
struct Couple {
     var name: String
     var value: AnyObject
}
let collection: [Couple] = ...
let preferences = CollectionPreferencesAdapter(
     collection: collection,
     mapKey: {$0.name}
     mapValue: {$0.value}
)

For instance NSHTTPCookieStorage which contains a collection of NSHTTPCookie conform now to protocol PreferencesType

2.0.4

02 Dec 14:00
Compare
Choose a tag to compare
  • Access application informations from NSBundle (which now conform to PreferencesType)
let bundle = NSBundle.mainBundle()
let applicationName = bundle[.CFBundleName] as? String
  • Add information about setup using Carthage

Carthage compatible

2.0.3

24 Nov 10:31
Compare
Choose a tag to compare
  • Operator or subscript to archive/convert object
userDefaults["mycolorkey", .Archive] = UIColor.blueColor()
  • any object could conform to PreferencesType by extending ReflectingPreferences
struct PreferenceStruct {
    var color: String = "red"
    var age: Int
    let enabled: Bool = true
}
extension PreferenceStruct: ReflectingPreferences {}
if pref["color"] as? String { .. }
  • PreferencesController to allow binding on all PreferencesType (inspired from NSUserDefaultsController) for OSX

2.0.2

01 Nov 23:00
Compare
Choose a tag to compare

New

Add tvOS, watchOS compatibility

Change

Change logo
Remove many redundant code using protocol extension
Move operators to a separate file

Fix

Fix Plist write immediatly if using one of set methods

2.0.1

30 Sep 14:53
Compare
Choose a tag to compare

Allow to get one preference (by key) using function and operator

var myPref: MutablePreference<Int> = myPreferences <| "aKey"
myPref++

2.0.0

18 Sep 10:43
Compare
Choose a tag to compare

Xcode7 and swift 2
Keychain support