반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- NullObject
- vim
- SwiftUI
- typeorm
- operator
- init
- nestjs
- @State
- Xcode
- RFC1738/1808
- SWIFT
- RxCocoa
- @EnvironmentObject
- @Binding
- Creating Operators
- swift6
- dismiss
- Operater
- nonisolated
- URL(string:)
- Bug
- Operators
- ios14
- @Environment
- subject
- IOS
- RxSwift
- NavigationLink
- init?
- graphql
Archives
- Today
- Total
Tunko Development Diary
RxSwift) Transforming Operators (startWith, concat) 본문
startWith
startWith는 옵저버블 앞수분에 다른 항목을 추가합니다.
startWith는 가변 파라미터 입니다.
let disposeBag = DisposeBag()
let emoticons = ["🍎", "🍊", "🥝", "🍉"]
Observable.from(emoticons)
.startWith("🍇")
.startWith("🍈")
.startWith("🍌", "🫐", "🍒")
.subscribe { print($0) }
.disposed(by: disposeBag)
출력
next(🍌)
next(🫐)
next(🍒)
next(🍈)
next(🍇)
next(🍎)
next(🍊)
next(🥝)
next(🍉)
completed
결과를 보면 가장 나중에 추가한 startWith가 가장 먼저 방출되는것을 확인할 수 있습니다.
concat
concat연산자는 두개의 옵저버블을 연결할 때 사용합니다.
let disposeBag = DisposeBag()
let numbers1_5 = Observable.from([1,2,3,4,5])
let numbers6_10 = Observable.from([6,7,8,9,10])
Observable.concat([numbers1_5, numbers6_10])
.subscribe{ print($0) }
.disposed(by: disposeBag)
numbers1_5.concat(numbers6_10)
.subscribe{ print($0) }
.disposed(by: disposeBag)
출력
next(1)
next(2)
next(3)
next(4)
next(5)
next(6)
next(7)
next(8)
next(9)
next(10)
completed
next(1)
next(2)
next(3)
next(4)
next(5)
next(6)
next(7)
next(8)
next(9)
next(10)
completed
반응형
'Development > RxSwift' 카테고리의 다른 글
RxSwift) Transforming Operators (combineLatest, zip) (0) | 2022.06.04 |
---|---|
RxSwift) Transforming Operators (merge) (0) | 2022.06.04 |
RxSwift) Transforming Operater (scan, buffer, window, groupBy) (0) | 2022.06.03 |
RxSwift) Transforming Operater (flatMap, flatMapFirst, flatMapLatest) (0) | 2022.06.02 |
RxSwift) Transforming Operator (toArray, map, compactMap) (0) | 2022.06.02 |
Comments