func getData(_ url: String) -> Observable<String?> {
return Observable.create() { emitter in
emitter.onNext("Hello World")
emitter.onCompleted()
return Disposables.create()
}
}
// 결과
// Optional("Hello World")
func getData(_ url: String) -> Observable<String?> {
return Observable.just("Hello World")
}
// 결과
// Optional("Hello World")
func getData(_ url: String) -> Observable<[String?]> {
return Observable.just(["Hello", "World"])
}
// 결과
// [Optional("Hello"), Optional("World")]
func getData(_ url: String) -> Observable<String?> {
return Observable.from(["Hello", "World"])
}
// 결과
// Optional("Hello")
// Optional("World")
_ = getData(MEMBER_LIST_URL)
.subscribe{ event in
switch event {
case .next(let t):
print(t)
break
case .error(let err):
break
case .completed:
break
}
}
_ = getData(MEMBER_LIST_URL)
.subscribe(onNext: { print($0) },
onError: { err in print(err) },
onCompleted: { print("Complete") } )
이렇게 간단하게 데이터 확인 가능!
downloadJson(MEMBER_LIST_URL)
.observeOn(MainScheduler.instance) // suger api
.subscribe(onNext: { json in
self.editView.text = json
self.setVisibleWithAnimation(self.activityIndicator, false)
})
downloadJson(MEMBER_LIST_URL)
.map { json in json?.count ?? 0 }
.filter { count in count > 0 }
.map { "\($0)" }
.observeOn(MainScheduler.instance) // suger : operator
.subscribe(onNext: { json in
self.editView.text = json
self.setVisibleWithAnimation(self.activityIndicator, false)
})
https://www.youtube.com/watch?v=iHKBNYMWd5I&list=PL03rJBlpwTaBrhux_C8RmtWDI_kZSLvdQ