__ _ __ _ _ _
/ _\_ _(_)/ _| |_ /\/\ __ _ __ _(_) ___ /\ /\___| |_ __ ___ _ __ ___
\ \\ \ /\ / / | |_| __|/ \ / _` |/ _` | |/ __|/ /_/ / _ \ | '_ \ / _ \ '__/ __|
_\ \\ V V /| | _| |_/ /\/\ \ (_| | (_| | | (__/ __ / __/ | |_) | __/ | \__ \
\__/ \_/\_/ |_|_| \__\/ \/\__,_|\__, |_|\___\/ /_/ \___|_| .__/ \___|_| |___/
|___/ |_|
Package for unify most useful helpers for your day a day coding.
public struct HelperManager {}
This helper provides methodf for encode and decode json to swift object and vice versa using Codable framework..
Description : function for encode Swift object to json stirng.
- Parameter result: Generic for pass object as argument for encode.
- Throws: NSError with message and code Int with error for manage.
- Returns: String: String format json as object encoded.
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.
}
Description: function for decode string json to swift object.
- Parameters:
- json: String json for decode.
- type: type identity as baseinterface of json conversion.
- Throws: NSError with message and code Int with error for manage.
- Returns: T?: Type of class provided in the constructor for decode this json.
public static func jsonDecode<T: Codable>(_ json: String, type: T.Type) throws -> T
Object:
mockStruct = MockObject(field1: "value1", field2: 1, field3: ["arrayvalue1", "arrayvalue2"], field4: MockObject2(mField1: "mValue1", mField2: 2, mField3: [0, 1, 2, 3, 4, 5, 6]))
use
do {
let decoded = try HelperManager.JSON.jsonDecode(jsonString, type: MockObject.self)
} catch let error as NSError {
//put here your error management.
}
This helper includes a fuction for catch top viewcontroller in Viewcycle stack
Description : function for encode Swift object to json stirng.
- Parameter base: Base of stack for find the top view controller.
- Returns: UIViewController: The first view controller finded in base stack.
public static func getTopViewController(base: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController?
let topVC = HelperManager.UIApplicationHelpers.getTopViewController()
David Martin Saiz – @deividmarshall – davms81@gmail.com
Distributed under the MIT license. See LICENSE
for more information.
https://github.com/CodeNationDev/
- 1.0.0
- JSON helper, encode and decode jsons.
- UIapplicationHelper for get top viewcontroller.
- UnitTesting
- Readme documentation.