Swiftpack.co - ElevatedUnderdogs/Callable as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by ElevatedUnderdogs.
ElevatedUnderdogs/Callable 1.4.0
A light weight Swift Package for making web calls
⭐️ 0
🕓 1 year ago
.package(url: "https://github.com/ElevatedUnderdogs/Callable.git", from: "1.4.0")

Callable

A light weight Swift Package for making web calls.

Swift Version License

Callable was created to solve the tiresome and tedius chore of writing URLSession.shared.dataTask etc. etc. etc.

Installation into a project

Copy the .git url for this repo.

Screen Shot 2021-04-03 at 10 11 14 PM Screen Shot 2021-04-03 at 10 11 31 PM

Paste it here:

Screen Shot 2021-04-03 at 10 12 07 PM

Click enter, then follow the prompts.

Installation into a package

Add this project on your Package.swift

import PackageDescription

let package = Package(
    dependencies: [
        .Package(url: "https://github.com/ElevatedUnderdogs/Callable.git", majorVersion: 0, minor: 0)
    ]
)

Usage example

You can simply specify your URL and then access either Data, JSON or through the magic of generics: a Codable type.

import Callable

URL(string: "http://api/website.com").callCodable { (myStruct: MyStruct?) in 
    print("The data", (myStruct == nil ? "doesn't convert": "converts"), "to MyStruct.")
}

URLRequest conforms to Callable as well, so you can do the same thing:

import Callable

let myURLRequest: URLRequest!
myURLRequest.callCodable { (myStruct: MyStruct?) in 
    print("The data", (myStruct == nil ? "doesn't convert": "converts"), "to MyStruct.")
}

Meta

Scott Lydon – Linkedin

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

ElevatedUnderdogs

GitHub

link
Stars: 0
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

Add error handler version of codable call.
1 year ago

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