Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

21 Commits

Repository files navigation

CombineExamples

WIP

👷 🧱 🧰 🛠️
Getting started with Combine
A collection of simple examples using Apple Combine reactive framework

last commitopen issuesswift versionplatformlicense
Built with ❤︎ by Pawel Krawiec


Examples

LOGIN SCREEN

Simple user login validation

letcredentials=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...



TIMER

Simplified stopwatch

Timer.publish(every:0.1, on:.main, in:.default).autoconnect().scan(0,{(acc, _ )inreturn acc +1}).map{ $0.timeInterval }.replaceError(with:"").eraseToAnyPublisher().assign(to: \.currentTime, on:self).cancelled(by: cancellableBag)
// More in the example...



SEARCH

Browsing GitHub repositories

$query
.throttle(for:0.5, scheduler:.main, latest:true).removeDuplicates().map{ query inreturnAPI().search(with: query).retry(3).eraseToAnyPublisher()}
// More in the example...



AVAILABILITY

Check if your repository name is already taken

 $text
.throttle(for:0.5, scheduler:.main, latest:true).map{ text inAPI().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.

About

Getting started with Apple Combine

Topics

Resources

Stars

168 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages