Monaka 0.0.3

Monaka 0.0.3

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Aug 2016
SPMSupports SPM

Maintained by naru.



Monaka 0.0.3

  • By
  • naru

Overview

Monaka convert custom struct to NSData.

Usage

Pack/Unpack Standard Variables

1.Activate

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
}

2.Pack/Unpack

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

Custom Struct

1.Make a custom struct confirm protocol 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)
    }
}

2.Activate

Activate your custom struct.

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

  Monaka.activateStandardPackables(withCustomStructActivations: {
    SampleStruct.activatePack()
  })

  // 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.