Code Monkey home page Code Monkey logo

flexiblemodelprotocol's Introduction

FlexibleModelProtocolImage

FlexibleModelProtocol

Model protocol with flexible, diverse types of conversion

Platform Cocoapods Compatible

Requirements

  • iOS 11.0+ / macOS 10.13+ / tvOS 13.0+ / watchOS 6.0+
  • Xcode 11+
  • Swift 5.0+

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate FlexibleModelProtocol into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'FlexibleModelProtocol', '~> 1.1'

Usage

example model

import FlexibleModelProtocol

struct MyModel: FlexibleModelProtocol {
    typealias selfType = MyModel
    ...
}

From Data

  • JSON
let myModel: MyModel? = MyModel.fromJson(jsonData: data)
  • XML
let myModel: MyModel? = MyModel.fromXML(xmlData: data)
  • Dictionary
let myModel: MyModel? = MyModel.fromDictionary(dictionary: data)
  • NSDictionary
let myModel: MyModel? = MyModel.fromNSDictionary(nsDictionary: data)

To Data

  • JSON
let jsonString: String = myModel.toJson()
  • XML
let xmlString: String? = myModel.toXML()
  • Dictionary
let dictionary: [String:Any]? = myModel.toDictionary()
  • NSDictionary
let nsDictionary: NSDictionary? = myModel.toNSDictionary()

Copy on Write

example model

struct MyModel: FlexibleModelProtocol {
    ...
}
struct MyCopyOnWriteModel: CopyOnWriteModelProtocol {
    typealias ModelType = MyModel
    var dataWrapper: DataWrapper<MyModel>? = nil
}

FlexibleModelProtocolModel to CopyOnWriteModelProtocolModel

let model: MyModel = MyModel(...)
var emptyCowObj: MyCopyOnWriteModel = MyCopyOnWriteModel()
let cowData: MyCopyOnWriteModel? = model.toCopyOnWriteModel(object: &emptyCowObj)

CopyOnWriteModelProtocolModel to FlexibleModelProtocolModel

let cowModel: MyCopyOnWriteModel = CowModel(dataWrapper: DataWrapper(originModel: MyModel(...)))
let flexibleModel: MyModel? = cowModel.toFlexibleProtocolModel()

* Sample Project *

I wrote an example of how to use it for the unit test.

Contact Us

Email : [email protected]

License

FlexibleModelProtocol is released under the MIT license. See LICENSE for details.

flexiblemodelprotocol's People

Contributors

hanweeeelee avatar

Stargazers

sangyeop avatar Chuck avatar  avatar Seon Yu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.