4시간에 RxSwift 마스터 하기
Branch: master
Clone or download
iamchiwon
iamchiwon mockaroo 를 사용한 목업 데이터 연동
async data fetch via mockaroo api
async avatar image
caching avatar image
Latest commit 61416cf Feb 11, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Example mockaroo api 사용해서 목업데이터 사용 Feb 11, 2019
docs
.gitignore update step1 example Jan 12, 2019
README.md add rx extension example gist Jan 26, 2019

README.md

RxSwift 4시간에 끝내기


Contents

1. 기본

동기/비동기

  • 동기
@IBAction func onLoadSync(_ sender: Any) {
    guard let url = URL(string: imageUrl1) else { return }
    guard let data = try? Data(contentsOf: url) else { return }
    
    let image = UIImage(data: data)
    imageView.image = image
}
  • 비동기
@IBAction func onLoadAsync(_ sender: Any) {
    DispatchQueue.global().async {
        guard let url = URL(string: self.imageUrl1) else { return }
        guard let data = try? Data(contentsOf: url) else { return }
        
        let image = UIImage(data: data)
        
        DispatchQueue.main.async {
            self.imageView.image = image
        }
    }
}

In computing, reactive programming is a declarative programming paradigm concerned with data streams and the propagation of change.


라이브러리

  • PromiseKit
promiseLoadImage(from: loadingImageUrl)
    .done { image in
        self.imageView.image = image
    }.catch { error in
        print(error.localizedDescription)
}
_ = rxswiftLoadImage(from: loadingImageUrl)
    .observeOn(MainScheduler.instance)
    .subscribe({ result in
        switch result {
        case let .next(image):
            self.imageView.image = image

        case let .error(err):
            print(err.localizedDescription)

        case .completed:
            break
        }
    })

Disposable/DisposeBag

var disposable: Disposable?
disposable?.dispose()
var disposeBag = DisposeBag()

2. 사용법


3. 응용


4. 확장


세미나 영상보기


License


이 저작물은 크리에이티브 커먼즈 저작자표시 2.0 대한민국 라이선스에 따라 이용할 수 있습니다.