Monaka convert custom struct and fundamental values to NSData (also nested array and dictionary).
You can persistent store of your defined struct. Your defined struct is for example 'latest selected tab index', 'array of struct fetched from API' or 'current application state'. I think these should be represented as simple struct and can be stored in application. Converted data can be written in file or NSUserDefault.
github "naru-jpn/Monaka"
pod 'Monaka'
Packable
variable ⇄ NSData.
// Pack
let value: Int = 10
let data: NSData = Monaka.pack(value)
// Unpack
let unpacked = Monaka.unpack(data) as? Int
struct Sample: CustomPackable {
let id: String
// Return new struct from applied properties.
static var restoreProcedure: ([String : Packable] -> Packable?) = { (properties: [String : Packable]) -> Packable? in
guard let id = properties["id"] as? String else {
return nil
}
return Sample(id: id)
}
}
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
Monaka.activate(Sample)
// Other codes...
return true
}
You can Pack/Unpack as standard types.
// Pack
let value: SampleStruct = SampleStruct(id: NSUUID().UUIDString)
let data: NSData = Monaka.pack(value)
// Unpack
let unpacked = Monaka.unpack(data) as? SampleStruct
Monaka is released under the MIT license. See LICENSE for details.