GitXplorerGitXplorer
d

PublisherView

public
7 stars
1 forks
0 issues

Commits

List of commits on branch main.
Verified
c3995803cee6008ec8fcdb326cf67f0b1037f7e0

Update swiftlint

ddanielctull committed 5 years ago
Verified
0ed68b720964ae9dda81123ef0fafcf896e2f18e

Add usage example

ddanielctull committed 5 years ago
Verified
dacef09022dc56501f63257f8ab53561c5128127

Add shields to readme

ddanielctull committed 5 years ago
Verified
f0554909db3348fd4e7417c5f22e3a2f54bf6804

Add swiftlint

ddanielctull committed 5 years ago
Verified
c384f2d1e6ca43a1a7149d99b3449945bbb21da6

Add license

ddanielctull committed 5 years ago
Verified
ac78bc712fc1fe145f3592463fb3d0fbe8abad85

Initial commit

ddanielctull committed 5 years ago

README

The README file for this repository.

PublisherView

Latest release Swift 5.1 Platforms: iOS, macOS, tvOS, watchOS

A SwiftUI view that subscribes to a Combine publisher to show different views for values and failures.

Usage

This can be used with a data task publisher which then decodes the data into model objects. In this example We display a list of posts when they are received or show the error message on screen if the task fails.

struct PostsView: View {
  // Get this publisher from somewhere, maybe a data task publisher
  let publisher: AnyPublisher<[Post], Error>
  var body: some View {
    PublisherView(publisher: publisher,
                  initial: LoadingView.init,
                  output: Content.init,
                  failure: FailureView.init)
  }
}

extension PostsView {

  fileprivate struct Content: View {
    let posts: [Post]
    var body: some View {
      List(posts) { post in
        Text(post.title)
      }
    }
  }
}

struct LoadingView: View {
  var body: some View {
    // Some awesome loading view
  }
}

struct FailureView: View {
  let error: Error
  var body: some View {
    Text(error.localizedDescription)
  }
}