Skip to content

The easiest way to deal with publishers within SwiftUI views

License

Notifications You must be signed in to change notification settings

denizcoskun/SubscriberView

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SubscriberView

SubscriberView is a simple SwiftUI View that deals with publishers in a much straightforward way.

Installation

Swift Package Manager

  • File > Swift Packages > Add Package Dependency
  • Add https://github.com/denizcoskun/SubscriberView.git
  • Select "Up to Next Major" with "1.0.1"

Usage

// without SubscriberView 

struct ContentView: View {
    let publisher = Just(0)
    @State let value: Int = 0
    
    var body: some View {
        Text(value)
            .onReceive(publisher) { value in
                self.value = value
            }
    }
}
// with SubscriberView
struct ContentView: View {
    let publisher = Just(0)

    var body: some View {
        SubscriberView(publisher) {
            Text("\($0)")
        }
    }
}

About

The easiest way to deal with publishers within SwiftUI views

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages