Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tailec/CombineExamples
Getting started with Apple Combine
https://github.com/tailec/CombineExamples
combine reactive reactive-programming swift
Last synced: 13 days ago
JSON representation
Getting started with Apple Combine
- Host: GitHub
- URL: https://github.com/tailec/CombineExamples
- Owner: tailec
- Created: 2019-06-20T12:17:59.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-09-10T13:33:43.000Z (about 2 years ago)
- Last Synced: 2024-01-25T03:16:04.512Z (10 months ago)
- Topics: combine, reactive, reactive-programming, swift
- Language: Swift
- Size: 521 KB
- Stars: 167
- Watchers: 4
- Forks: 14
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-combine - Combine Examples
README
CombineExamples
WIP
👷 🧱 🧰 🛠️
Getting started with Combine
A collection of simple examples using Apple Combine reactive framework
Built with ❤︎ by
Pawel Krawiec
## Examples
Simple user login validation
```swift
let credentials = Publishers
.CombineLatest($username, $password) { ($0, $1) }
.share()
credentials
.map { uname, pass in
uname.count >= 4 && pass.count >= 4
}
.prepend(false) // initial state
.assign(to: \.isEnabled, on: loginButton)
.cancelled(by: cancellableBag)
// More in the example...
```
Simplified stopwatch
```swift
Timer.publish(every: 0.1, on: .main, in: .default)
.autoconnect()
.scan(0, { (acc, _ ) in return acc + 1 })
.map { $0.timeInterval }
.replaceError(with: "")
.eraseToAnyPublisher()
.assign(to: \.currentTime, on: self)
.cancelled(by: cancellableBag)
// More in the example...
```
Browsing GitHub repositories
```swift
$query
.throttle(for: 0.5,
scheduler: .main,
latest: true)
.removeDuplicates()
.map { query in
return API().search(with: query)
.retry(3)
.eraseToAnyPublisher()
}
// More in the example...
```
Check if your repository name is already taken
```swift
$text
.throttle(for: 0.5, scheduler: .main, latest: true)
.map { text in
API().search(with: text)
.map { isAvailable in
isAvailable ? "Name available" : "Name already taken"
}
.prepend("Checking...")
}
.switchToLatest()
// More in the example...
```
Stay tuned. More examples coming.
## Licence
MIT.The Apple logo and the Combine framework are property of Apple Inc.