Skip to content

Latest commit

 

History

History
39 lines (30 loc) · 975 Bytes

README.md

File metadata and controls

39 lines (30 loc) · 975 Bytes

ios-StandardDefaults

A wrapper around standard UserDefaults for getting/setting values using Swift subscript method, with ability to store enums containing a rawValue.

Usage Example

//1. storing any value
StandardDefaults["com.number.example"] = 4
if let number: Int = StandardDefaults["com.number.example"] {
    print(number)
}

//2. storing enum value
enum AnyEnum: Int {
    case CaseOne
    case CaseTwo
}


StandardDefaults["com.enum.example"] = AnyEnum.CaseOne
if let anyEnum: AnyEnum = StandardDefaults["com.enum.example"] {
    print(ido)
}

Dynamic Member Lookup support

StandardDefaults also supports this nice feature of Swift language. This means you can access saved value directly bypassing the subscript syntax.

StandardDefaults["name"] = "German"
if let name = StandardDefaults<String>.name {
    print(name)
}