Swiftpack.co -  markiv/Fondue as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
markiv/Fondue
A library of delightfully light extensions to simplify working with SwiftUI and Combine in real-world apps
.package(url: "https://github.com/markiv/Fondue.git", from: "1.0.7")

Swift

Fondue 🫕

A library of delightfully light extensions to simplify working with SwiftUI and Combine in real-world apps.

Literal URLs

URL is now ExpressibleByStringLiteral, so we can conveniently express them like this:

let url: URL = "https://server.domain/path"

We've deliberately restricted this to literal strings, since it's reasonable to expect that they're as free of typos as your code. 😉

URL Parameters

We've taught URL to deal with query parameters like a dictionary[^1]:

url.parameters["query"] = "fondue"

[^1]: Strictly speaking, URLs can have multiple parameters with the same name (e.g. a=1&a=2), and some server-side frameworks gather these into arrays. But in many real-life projects, we think of each parameter as uniquely-named. If this is also your case, you might find it more convenient to treat query parameters just like a dictionary.

URL & URLRequest Modifiers

Inspired by SwiftUI's extensive use of modifiers, we've given a few to URL and URLRequest:

let base: URL = "https://server.domain/api"
let url = base.with(parameters: ["query": "fondue"])
 
let request = url.request(.post, path: "path")
    .adding(parameters: ["page": 1])

URL.request() and URLRequest.publisher()

Getting a Combine publisher from URLRequest or URL couldn't be simpler:

let base: URL = "https://api.foo.com/api/employees"

func employee(id: String) -> AnyPublisher<Employee, Error> {
    base.request(path: id).publisher()
}

The new modifiers let you fluently set HTTP method, headers and automatic body encoding, for example:

func createToken(email: String, password: String) -> AnyPublisher<TokenResponseBody, Error> {
    base.request(.post, path: "UserProfiles/CreateToken")
        .adding(header: "ApplicationToken", value: applicationToken)
        .with(body: TokenRequestBody(email: email, password: password))
        .publisher()
}

ObservableProcessor

A convenient way to provide asynchronous data to a View. It publishes the output, busy and error states so that they can be bound to a View.

struct SomeView: View {
    @StateObject var model = ObservableProcessor { SomeAPI.get() }
    
    var body: some View {
        List(model.output ?? []) { item in
            :
        }
    }
}

GitHub

link
Stars: 2
Last commit: 2 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