Latest | 2.0.3 |
---|---|
Homepage | https://github.com/mozhenhau/D3Json |
License | MIT |
Platforms | ios 8.0, requires ARC |
Authors |
D3Json
通过swift的反射特性,把json数据转换为model对象,本类最主要是解决了其他一般json转换类不能转换自定义对象的问题
只有一个文件:D3Json.swfit
自定义类需要@objc(XXX), 继承D3Model,可以参照例子
Usage
例子在D3Model的Project里面,写了两个测试,一个是json转单model,一个是转model的list
只需要一句代码:
var user:User = User.jsonToModel(json)
就可以把json数据转换成User类
转成list对象:
var users = User.jsonToModelList(jsonArr) as! Array
就可以把json数据转换成Array
Problem
- model属性基础类型需要初始化
- 因为swift的反射reflect的缺陷,父类的属性暂不转换
Requirements
- iOS 7.0+ / Mac OS X 10.9+
- Xcode 6.1
Integration
CocoaPods (iOS 8+, OS X 10.9+)
You can use CocoaPods to install D3Json adding it to your Podfile:
platform :ios, '7.0'
use_frameworks!
pod 'D3Model', '~> 2.0.3'
you need import D3Model
Note that it needs you to install CocoaPods 36 version, and requires your iOS deploy target >= 8.0:
[sudo] gem install cocoapods -v '>=0.36'
Manually
drag D3Model.swift to the project
Latest podspec
{ "name": "D3Model", "version": "2.0.3", "license": { "type": "MIT", "file": "LICENSE" }, "homepage": "https://github.com/mozhenhau/D3Json", "authors": { "mozhenhau": "[email protected]" }, "summary": "ARC and GCD Compatible D3Json Class for iOS and OS X.", "source": { "git": "https://github.com/mozhenhau/D3Json.git", "tag": "2.0.3" }, "source_files": "D3Model/D3Model.swift", "requires_arc": true, "platforms": { "ios": "8.0" } }
Fri, 04 Mar 2016 14:28:04 +0000