Giter VIP home page Giter VIP logo

combineexamples's Introduction

CombineExamples

WIP

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

last commit open issues swift version platform license
Built with ❤︎ by Pawel Krawiec


Examples

LOGIN SCREEN

Simple user login validation

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



TIMER

Simplified stopwatch

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



SEARCH

Browsing GitHub repositories

$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...



AVAILABILITY

Check if your repository name is already taken

 $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.

combineexamples's People

Contributors

tailec avatar nanujogi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.