Swiftpack.co - Package - koher/obtap

Obtap

Obtap provides the Tap type which works like a water tap for publishers. The Tap type is especially useful when it is combined with SwiftUI.

import SwiftUI
import Combine
import Obtap

struct UserList: View {
    private var users: Tap<[User], Never> = .init {
        Future<[User], Never> { promise in
            fetchUsers { (users: Result<[User], Error>) in
                promise(users.flatMapError { _ in .success([]) })
            }
        }
    }
    
    var body: some View {
        let users: [User] = self.users.get()
        return List(users) { user in
            Text(user.name)
        }
        .onAppear { self.users.isOn = true }
        .onDisappear { self.users.isOn = false }
    }
}

License

MIT

Github

link
Stars: 0

Dependencies

Used By

Total: 0

Releases

0.1.0-alpha - 2020-09-16 03:07:07

This is the first pre-release of Obtap. It is available through SwiftPM.