Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/naru-jpn/Monaka
Monaka convert custom struct to NSData.
https://github.com/naru-jpn/Monaka
Last synced: 8 days ago
JSON representation
Monaka convert custom struct to NSData.
- Host: GitHub
- URL: https://github.com/naru-jpn/Monaka
- Owner: naru-jpn
- License: mit
- Created: 2016-08-19T07:34:40.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-08-26T22:56:10.000Z (over 8 years ago)
- Last Synced: 2024-11-13T06:49:41.668Z (29 days ago)
- Language: Swift
- Homepage:
- Size: 679 KB
- Stars: 22
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ios - Monaka - Convert custom struct and fundamental values to NSData. (Data Structures / Algorithms / Getting Started)
- awesome-ios-star - Monaka - Convert custom struct and fundamental values to NSData. (Data Structures / Algorithms / Getting Started)
- fucking-awesome-ios - Monaka - Convert custom struct and fundamental values to NSData. (Data Structures / Algorithms / Getting Started)
- fucking-awesome-ios - Monaka - Convert custom struct and fundamental values to NSData. (Data Structures / Algorithms / Getting Started)
README
# Monaka
[![Swift](https://img.shields.io/badge/swift-2.2-orange.svg?style=flat)](#)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![Platform](https://img.shields.io/badge/platform-ios-lightgrey.svg?style=flat)](#)
[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://opensource.org/licenses/MIT)## Overview
Monaka convert custom struct and fundamental values to NSData (also nested array and dictionary).
## Purpose
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.
## Installation
### Carthage
```
github "naru-jpn/Monaka"
```### CocoaPods
```
pod 'Monaka'
```## Usage
### For Standard Variables
`Packable` variable ⇄ NSData.
```swift
// Pack
let value: Int = 10
let data: NSData = Monaka.pack(value)// Unpack
let unpacked = Monaka.unpack(data) as? Int
```### For Custom Struct
#### 1.Make a custom struct confirming protocol `CustomPackable`
```swift
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.
```swift
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.
```swift
// 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.