rbaumbach/Utensils

A set of useful iOS tools.


License
MIT

Documentation

Utensils Cocoapod Version Swift Version SPM Compatible Cocoapod Platform iOS Deployment Target License

A set of useful iOS tools.

Adding Utensils to your project

CocoaPods

CocoaPods is the recommended way to add Utensils to your project.

  1. Add Utensils to your Podfile pod 'Utensils'.
  2. Install the pod(s) by running pod install.
  3. Add Utensils to your files with import Utensils.

Swift Package manager

Swift Package Manager can be used to add Utensils the to your project:

  1. Add .package(url: "https://github.com/rbaumbach/Utensils", from: "0.7.0")
  2. Follow intructions to add the Utensils package to your project.

Clone from Github

  1. Clone repository from github and copy files directly, or add it as a git submodule.
  2. Add all files from Source directory to your project.

What tools?

  • A Debouncer:
let debouncer = Debouncer()

debouncer.mainDebounce(seconds: 0.1) {
    thingy.doExpensiveWork()
}
  • A Directory:
let directory = Directory(.temp(additionalPath: "filez/"))
  • A persistence tool called Trunk:
let trunk = Trunk()

trunk.save(data: [0, 1, 2, 3, 4])

let arrayOfInts: [Int]? = trunk.load()
  • An AppLaunchViewController

Using the default launch view:

let appLaunchViewController = AppLaunchViewController { print("I'm launching!") }

Using a custom user supplied view:

let appLaunchViewController = AppLaunchViewController { thingy.doSomethingLengthyBeforeAppLaunches() }
appLaunchViewController.customLoadingView = fancyBrandedLoadingView

Note: The custom view will be anchored to all 4 corners of view controller

  • A generic Validator
let email = Email(string: "billy@goat.com")

let isValidEmail = AnyValidator<Email>().isValid(email)
  • A json FileLoader
do {
    let decodedJSON: Model? = try FileLoader().loadJSON(name: "file", fileExtension: "json")
} catch {
    // handle error
}
  • A "pequeno" networker
// Using basic baseURL init()

let networker = PequenoNetworking(baseURL: "https://dogsrbettahthancats.party")

// Using global BaseURL contained within UserDefaults

UserDefaults.standard.set("https://dogsrbettahthancats.party",
                          forKey: PequenoNetworkingConstants.BaseURLKey)

let networker = PequenoNetworking()

// Ol' skool Any json response

networker.get(endpoint: "/dogs",
              headers: ["version": "v1"],
              parameters: ["breed": "chihuahua"],
              completionHandler: { result in print(result) }

// Using Codable models
                
networker.get(endpoint: "/dogs",
              headers: ["version": "v1"],
              parameters: ["breed": "chihuahua"]) { (result: Result<[Dog], Error>) in
    print(result))
}

Note: The Dog model must conform to Codable

  • A Printer
let dog = Dog()

let printer = Printer(printType: .lite)

printer.print(dog)

// Prints -> "Name: Sparky"

Note: The Dog model must conform to Printable

  • JSONCodable type that can be used with Codable

This can be used if you don't fully know your JSON types at compile time:

let jsonCodableDictionary: [String: JSONCodable] = [
    "favorite-cucumber": nil,
    "name": "some-jsons",
    "lucky": 777,
    "gpa": 4.0,
    "almost-an-a+": 99.99,
    "loves-tacos": true,
    "burrito": [
        "carne": "asada",
        "arroz": "spanish",
        "salsa": "rojo",
        "frijoles": "pinto"
    ],
    "dog": [
        "name": "maya",
        "age": 3,
        "breed": ["chihuahua", "miniature-pinscher"],
        "loves-dog-food": false
    ],
    "hobbies": ["bjj", "double-dragon", "drums"],
    "numbers": ["uno", 2, 3.5]
]

And more to come...

Goodies

All tools will have accompanying protocols and fakes for those of you that enjoy testing your software. This allows you to program your application to this "interface" and then you can stub it out with your own fake implementation for unit tests.

Testing

This project has been setup to use fastlane to run the specs.

First, bundle required gems, install Cocoapods. Next, inside the root project directory run:

$ bundle
$ bundle exec pod install

And then use fastlane to run all the specs on the command line:

$ bundle exec fastlane specs

Suggestions, requests, and feedback

Thanks for checking out Utensils. Any feedback, suggestions and feedback can be can be sent to: github@ryan.codes, or opened as a github issue.