Model protocol with flexible, diverse types of conversion
- iOS 11.0+ / macOS 10.13+ / tvOS 13.0+ / watchOS 6.0+
- Xcode 11+
- Swift 5.0+
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'
import FlexibleModelProtocol
struct MyModel: FlexibleModelProtocol {
typealias selfType = MyModel
...
}
- 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)
- 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()
struct MyModel: FlexibleModelProtocol {
...
}
struct MyCopyOnWriteModel: CopyOnWriteModelProtocol {
typealias ModelType = MyModel
var dataWrapper: DataWrapper<MyModel>? = nil
}
let model: MyModel = MyModel(...)
var emptyCowObj: MyCopyOnWriteModel = MyCopyOnWriteModel()
let cowData: MyCopyOnWriteModel? = model.toCopyOnWriteModel(object: &emptyCowObj)
let cowModel: MyCopyOnWriteModel = CowModel(dataWrapper: DataWrapper(originModel: MyModel(...)))
let flexibleModel: MyModel? = cowModel.toFlexibleProtocolModel()
Email : [email protected]
FlexibleModelProtocol is released under the MIT license. See LICENSE for details.