Monaka convert custom struct to NSData.

Overview

Monaka

Swift Carthage compatible Platform License

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.

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

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.

You might also like...
A Currency Converter & Calculator IOS application to check, convert and calculate to popular currencies to your favorite ones.
A Currency Converter & Calculator IOS application to check, convert and calculate to popular currencies to your favorite ones.

A Currency Converter & Calculator IOS application to check, convert and calculate to popular currencies to your favorite ones.

Swiftly convert country codes and cultural terms to all 269 emoji flags without hassle
Swiftly convert country codes and cultural terms to all 269 emoji flags without hassle

Swiftly convert country codes and cultural terms to all 269 emoji flags without hassle

Convert text with HTML tags, links, hashtags, mentions into NSAttributedString. Make them clickable with UILabel drop-in replacement.
Convert text with HTML tags, links, hashtags, mentions into NSAttributedString. Make them clickable with UILabel drop-in replacement.

Atributika is an easy and painless way to build NSAttributedString. It is able to detect HTML-like tags, links, phone numbers, hashtags, any regex or

Convert numeric addresses to symbols with callStackSymbols and dSYM.
Convert numeric addresses to symbols with callStackSymbols and dSYM.

Symbolicator Convert numeric addresses to symbols with callStackSymbols and dSYM files. Installation Supports Swift Package Manager.

A Cocoa NSFormatter subclass to convert dates to and from ISO-8601-formatted strings. Supports calendar, week, and ordinal formats.
A Cocoa NSFormatter subclass to convert dates to and from ISO-8601-formatted strings. Supports calendar, week, and ordinal formats.

ISO 8601: The only date format worth using Obligatory relevant xkcd: How to use this code in your program Add the source files to your project. Parsin

Convert text with HTML tags, links, hashtags, mentions into NSAttributedString. Make them clickable with UILabel drop-in replacement.
Convert text with HTML tags, links, hashtags, mentions into NSAttributedString. Make them clickable with UILabel drop-in replacement.

Convert text with HTML tags, links, hashtags, mentions into NSAttributedString. Make them clickable with UILabel drop-in replacement.

Swift package to convert a HTML table into an array of dictionaries.

Swift package to convert a HTML table into an array of dictionaries.

ips2crash is a macOS command line too to convert a .ips file to a legacy .crash log file.

Synopsis ips2crash is a macOS command line too to convert a .ips file to a legacy .crash log file. Motivation It should be possible to read .ips file

Convert HEIC images to JPEG format on the Mac

heic2jpeg Convert HEIC images to JPEG format on the Mac A basic tool to convert Apple's obnoxious HEIC format images (as the default photo format for

Convert the image to hexadecimal to send the image to e-paper

ConvertImageToHex Convert the image to hexadecimal to send the image to e-paper Conversion Order // 0. hex로 변환할 이미지 var image = UIImage(named: "sample

A common use case is wanting to convert device identifiers such as iPhone10,1 to a user friendly name; iPhone 8.

Devices Swift package that contains all devices from https://www.theiphonewiki.com/wiki/Models. A common use case is wanting to convert device identif

CLT to convert JSON5 to JSON

JSON5toJSON A small command line tool to convert JSON5 to JSON. Runs on macOS 12 (Monterey). Installation Install using Mint. $ mint install auramagi/

Convert live photos and videos into animated GIFs in iOS, or extract frames from them.
Convert live photos and videos into animated GIFs in iOS, or extract frames from them.

Create a GIF from the provided video file url, Or extract images from videos. This repository has been separated from original repo along with some no

Convert UIImage to ASCII art
Convert UIImage to ASCII art

BKAsciiImage As seen on Cmd.fm iOS App https://itunes.apple.com/app/cmd.fm-radio-for-geeks-hackers/id935765356 Installation BKAsciiImage is available

Style Art library process images using COREML with a set of pre trained machine learning models and convert them to Art style.
Style Art library process images using COREML with a set of pre trained machine learning models and convert them to Art style.

StyleArt Style Art is a library that process images using COREML with a set of pre trained machine learning models and convert them to Art style. Prev

A pure Swift library that allows you to easily convert SwiftUI Colors to Hex String and vice versa.
A pure Swift library that allows you to easily convert SwiftUI Colors to Hex String and vice versa.

iOS · macOS · watchOS · tvOS A pure Swift library that allows you to easily convert SwiftUI Colors to Hex String and vice versa. There is also support

Convert an IPA (iOS) to mac App (M1)

Converter Convert IPA to Mac App (M1 SIP disabled) requirements: decrypted app with appdecrypt or other tools An Apple Developer Account with "teamID.

Util for generation RSA keys on your client and save to keychain or convert into Data 🔑 🔐

RSASwiftGenerator 🔑 🔐 To run the example project, clone the repo, and run pod install from the Example directory first. Requirements ⚠️ SWIFT 4 XCod

Convert Countries, Country Codes, Continents,... with a single line of code.
Convert Countries, Country Codes, Continents,... with a single line of code.

iOS · macOS · watchOS · tvOS A pure Swift library that allows you to easily convert Countries to Country Codes and Country Codes to Countries. There i

Owner
Naruki Chigira
iOS application engineer.
Naruki Chigira
RandMyMod base on your own struct or class create one or a set of instance, which the variable's value in the instance is automatic randomized.

RandMyMod is an IOS Native Framework helps you generate one or a set of variable base on your own model. No matter your model is Class / Struct. Insta

郭介騵 17 Sep 24, 2022
Convert your own struct/enum to AnyObject easily.

AnyObjectConvertible Convert your own struct/enum to AnyObject easily. Sumally We can cast everything as AnyObject at Swift3.0 ?? So, we would not nee

tarunon 62 Feb 2, 2022
NSData Detector with swift

NSDataDetector This playground demonstrates a weird difference in behaviour between Xcodes 12.5.1 and 13.1 regarding NSDataDetector. Try to run it usi

Vinícius Rodrigues de Uzêda 0 Dec 7, 2021
Alamofire extension for serialize NSData to SwiftyJSON

Alamofire-SwiftyJSON An extension to make serializing Alamofire's response with SwiftyJSON easily. ⚠️ To use with Swift 3.x please ensure you are usin

SwiftyJSON 1.4k Dec 22, 2022
RandMyMod base on your own struct or class create one or a set of instance, which the variable's value in the instance is automatic randomized.

RandMyMod is an IOS Native Framework helps you generate one or a set of variable base on your own model. No matter your model is Class / Struct. Insta

郭介騵 17 Sep 24, 2022
A protocol that allows any class to be printed as if it were a struct or a JSON object.

ReflectedStringConvertible A protocol that extends CustomStringConvertible and uses reflection to add a detailed textual representation to any class.

Matt Comi 65 Dec 24, 2022
A simple class that wraps the process of saving or loading a struct or class into a single file

EZFile This is a simple class that wraps the process of saving or loading a stru

null 7 May 16, 2022
JSONHelper - ✌ Convert anything into anything in one operation; JSON data into class instances, hex strings into UIColor/NSColor, y/n strings to booleans, arrays and dictionaries of these; anything you can make sense of!

JSONHelper Convert anything into anything in one operation; hex strings into UIColor/NSColor, JSON strings into class instances, y/n strings to boolea

Baris Sencan 788 Jul 19, 2022
ObjectMapper is a framework written in Swift that makes it easy for you to convert your model objects to and from JSON.

ObjectMapper is a framework written in Swift that makes it easy for you to convert your model objects (classes and structs) to and from J

Tristan Himmelman 9k Jan 2, 2023
Convert text with HTML tags, links, hashtags, mentions into NSAttributedString. Make them clickable with UILabel drop-in replacement.

Atributika is an easy and painless way to build NSAttributedString. It is able to detect HTML-like tags, links, phone numbers, hashtags, any regex or

Pavel Sharanda 1.1k Dec 26, 2022