__          _  __ _                      _                 _                     
/ _\_      _(_)/ _| |_  /\/\   __ _  __ _(_) ___  /\  /\___| |_ __   ___ _ __ ___ 
\ \\ \ /\ / / | |_| __|/    \ / _` |/ _` | |/ __|/ /_/ / _ \ | '_ \ / _ \ '__/ __|
_\ \\ V  V /| |  _| |_/ /\/\ \ (_| | (_| | | (__/ __  /  __/ | |_) |  __/ |  \__ \
\__/ \_/\_/ |_|_|  \__\/    \/\__,_|\__, |_|\___\/ /_/ \___|_| .__/ \___|_|  |___/
                                    |___/                    |_|                  

该软件包统一了您日常编码中最有用的助手工具。

主要类

public struct HelperManager {}

助手工具

JSON

此助手工具提供使用 Codable 框架将 JSON 编码和解码为 Swift 对象的方法,反之亦然。

接口:

描述:将 Swift 对象编码为 JSON 字符串的函数。

public static func jsonEncode<T: Codable>(_ result: T) throws -> String

使用示例:

do {
let encoded = try HelperManager.JSON.jsonEncode(mockStructure)
} catch let error as NSError {
    //put here your error management.
}

解码:

描述: 将 JSON 字符串解码为 Swift 对象的函数。

public static func jsonDecode<T: Codable>(_ json: String, type: T.Type) throws -> T 

使用示例:

对象

mockStruct = MockObject(field1: "value1", field2: 1, field3: ["arrayvalue1", "arrayvalue2"], field4: MockObject2(mField1: "mValue1", mField2: 2, mField3: [0, 1, 2, 3, 4, 5, 6]))

使用

do {
let decoded = try HelperManager.JSON.jsonDecode(jsonString, type: MockObject.self)
} catch let error as NSError {
    //put here your error management.
}

UIApplication+TopViewController

此助手工具包含一个函数,用于捕获视图循环堆栈中的顶部视图控制器。

接口:

描述:将 Swift 对象编码为 JSON 字符串的函数。

public static func getTopViewController(base: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController?

使用示例:

let topVC = HelperManager.UIApplicationHelpers.getTopViewController()

元数据

David Martin Saiz – @deividmarshalldavms81@gmail.com

在 MIT 许可下分发。 有关更多信息,请参阅 LICENSE

https://github.com/CodeNationDev/

版本历史