TestsTested | ✓ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Aug 2016 |
SPMSupports SPM | ✗ |
Maintained by naru.
Monaka convert custom struct to NSData.
Write activation codes.
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
Monaka.activateStandardPackables(withCustomStructActivations: { /* Write here if you use your struct to pack. */ })
// Other codes...
return true
}
You can Pack/Unpack Packable
variable.
// For example, simple Int variable.
// Pack
let value: Int = 10
let data: NSData = Monaka.pack(value)
// Unpack
let unpacked = Monaka.unpack(data) as? Int
CustomPackable
// Protocol `CustomPackable`
struct SampleStruct: CustomPackable {
let id: String
/* Implementations */
// Implement function ([String : Packable] -> Packable?) named 'restoreProcedure'
static var restoreProcedure: [String : Packable] -> Packable? = { (dictionary: [String : Packable]) -> Packable? in
guard let id = dictionary["id"] as? String else {
return nil
}
return SampleStruct1(id: id)
}
}
Activate your custom struct.
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
Monaka.activateStandardPackables(withCustomStructActivations: {
SampleStruct.activatePack()
})
// 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.