/SMLTool

swift 常用工具合集、模型与字典转换、字符串转换、加密工具、常见属性扩展

Primary LanguageSwiftMIT LicenseMIT

SMLTool

CI Status Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

SMLTool is available through CocoaPods. To install it, simply add the following line to your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/songmenglong/SMLSpec.git'

pod 'SMLTool'

使用说明

swift字典与model转换

// Model转字典
let model = People(name: "张三", sex: 0, age: 30)
guard let dict = ModelEncoder.encoder(toDictionary: model) else {
    return
}
debugPrint("", dict)

// 字典转Model
let dict: [String: Any] = ["sex": 1, "age": 32, "name": "李四"]
guard let model = try? ModelDecoder.decode(People.self, param: dict) else {
    return
}
debugPrint("", model)

json字符串与字典转换

// JSON转字典
let json = "{\"name\":\"刘大\",\"age\":25,\"sex\":1}"
guard let dict = JSONTool.translationJsonToDic(from: json) else {
    return
}
debugPrint("", dict)

// 字典转JSON
let dict: [String: Any] = ["sex": 1, "age": 27, "name": "王五"]
guard let json = JSONTool.translationObjToJson(from: dict) else {
    return
}
debugPrint("", json)

Author

songmenglong, 983174628@qq.com

License

SMLTool is available under the MIT license. See the LICENSE file for more info.