Monaka
Overview
Monaka convert custom struct and fundamental values to NSData (also nested array and dictionary).
Installation
Carthage
github "naru-jpn/Monaka"
CocoaPods
pod 'Monaka'
Usage
For Standard Variables
Packable
variable ⇄ NSData.
// Pack
let value: Int = 10
let data: NSData = Monaka.pack(value)
// Unpack
let unpacked = Monaka.unpack(data) as? Int
For Custom Struct
CustomPackable
1.Make a custom struct confirming protocol 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)
}
}
2.Activate your custom struct.
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
Monaka.activate(Sample)
// Other codes...
return true
}
3.Pack/Unpack
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
License
Monaka is released under the MIT license. See LICENSE for details.