Swiftpack.co -  CodeNationDev/SwiftMagicHelpers as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
CodeNationDev/SwiftMagicHelpers
Scalable helpers library for Swift
.package(url: "https://github.com/CodeNationDev/SwiftMagicHelpers.git", from: "1.0.0")
 __          _  __ _                      _                 _                     
/ _\_      _(_)/ _| |_  /\/\   __ _  __ _(_) ___  /\  /\___| |_ __   ___ _ __ ___ 
\ \\ \ /\ / / | |_| __|/    \ / _` |/ _` | |/ __|/ /_/ / _ \ | '_ \ / _ \ '__/ __|
_\ \\ V  V /| |  _| |_/ /\/\ \ (_| | (_| | | (__/ __  /  __/ | |_) |  __/ |  \__ \
\__/ \_/\_/ |_|_|  \__\/    \/\__,_|\__, |_|\___\/ /_/ \___|_| .__/ \___|_|  |___/
                                    |___/                    |_|                  

Package for unify most useful helpers for your day a day coding.

Main class

public struct HelperManager {}

Helpers

JSON

This helper provides methodf for encode and decode json to swift object and vice versa using Codable framework..

Interface:

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

Usage Example:

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

Deocde:

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 

Usage Example:

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.
}

UIApplication+TopViewController

This helper includes a fuction for catch top viewcontroller in Viewcycle stack

Interface:

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?

Usage Example:

let topVC = HelperManager.UIApplicationHelpers.getTopViewController()

Meta

David Martin Saiz – @deividmarshalldavms81@gmail.com

Distributed under the MIT license. See LICENSE for more information.

https://github.com/CodeNationDev/

Version History

  • 1.0.0
    • JSON helper, encode and decode jsons.
    • UIapplicationHelper for get top viewcontroller.
    • UnitTesting
    • Readme documentation.

GitHub

link
Stars: 0
Last commit: 4 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics