Skip to content

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

License

Notifications You must be signed in to change notification settings

songmenglong/SMLTool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published