Swift5의 Result Type을 사용하면 비동기 API쪽 코드(데이터 받아와서 디코딩해주는..)를 간단하고 명확하게 만들 수 있다 [ 1 ] 그전에는.. 1) 옵셔널로 구분 func fetchModel(completion: @escaping (T?) -> Void) { let url = URL(string: "...")! URLSession.shared.dataTask(with: url) { data, response, error in guard let data = data else { return completion(nil) } guard let model = try? JSONDecoder().decode(T.self, from: data) else { return completion(nil) }..
Combining Operators 중 대표적인 두가지를 살펴보자 [ 1 ] withLatestFrom ObservableType extension에 가보면 public func withLatestFrom(_ second: SecondO) -> Observable { return WithLatestFrom(first: asObservable(), second: second.asObservable(), resultSelector: { $1 }) } 이렇게 구현되어있다 어떤 옵져버블 뒤에 withLatestFrom(Observable) 해주면 어떤 옵져버블의 이벤트가 발행될때마다 매개변수로 넘겨준 observable의 the latest element를 얻는다 예제를 보는 게 이해가 빠르다 --! let b..
reduce는 모든 이벤트들을 다 더한 총합을 방출하고 scan은 하나씩 더할 때마다 증가된 sum을 각각 방출한다 [ 1 ] Reduce Observable.of(1,2,3,4,5).reduce(0,accumulator: +) .subscribe(onNext: { print($0) }).disposed(by: disposeBag) // 출력값 15 [ 2 ] Scan Observable.of(1,2,3,4,5).scan(0, accumulator: +) .subscribe(onNext: { print($0) }).disposed(by: disposeBag) // 출력값 1 3 6 10 15 Reference https://rxmarbles.com
늘 헷갈리니 기록을 하자 🙂 Xcode상에서 UILabel과 같은 오브젝트를 클릭하면 다음과 같이 두개의 Priority를 설정할 수 있다 1) Hugging priority 우선순위가 높으면 내 크기 유지. 우선순위 낮으면 크기 늘어남 (늘어난다 = 당겨진다 = 커진다) 2) Compression Resistance priority 우선순위가 높으면 내 크기 유지. 우선순위 낮으면 크기 작아짐 (밀린다 = 찌그러진다 = 작아진다) 두 오브젝트 중 하나가 커져야하는 상황 -> Hugging priority 쓰고 두 오브젝트 중 하나가 작아져야하는 상황 -> Resistance priority 쓴다 (밑에서 자세하게 설명--!)[ 1 ] Hugging priority 두 개의 UILabel로 두 prior..
Observable을 만들어주는 생성 operator인 of와 from of vs from 배열을 넘겨주면 of 는 Observable을 만들고 from은 배열의 각각 원소들을 Observable로 만든다 let observableByOf = Observable.of([1,2,3]) let observableByFrom = Observable.from([1,2,3]) observableByOf의 타입은 Observable observableByFrom의 타입은 Observable 이다 Observable.of([1,2,3]).subscribe(onNext: { array in print(array) }).disposed(by: disposeBag) Observable.from([1,2,3]).subscr..
Map vs FlatMap 1) Map get value from stream and return another value of whatever type, result is Observable. 2) FlatMap get value from stream and return an Observable of whatever type. Map map은 이벤트를 바꾼다. E Type이벤트를 R Type이벤트로 바꾼다 public func map(_ transform: @escaping (Self.E) throws -> R) -> RxSwift.Observable FlatMap flatMap은 이벤트를 다른 observable로 바꾼다 public func flatMap(_ selector: @escaping (E..
시나리오 import RxSwift import RxCocoa let disposeBag = DisposeBag() struct Student { var score: BehaviorRelay } let john = Student(score: BehaviorRelay(value: 75)) let mary = Student(score: BehaviorRelay(value: 95)) let student = PublishSubject() score을 가지고 있는 Student 타입을 관찰하기 위해 student라는 subject를 만들었다 [ 1 ] FlatMap student.flatMap { $0.score } .subscribe(onNext: { print($0) }).disposed(by: dispos..
[ 1 ] Unit Testing 이란 implement the feature and write the test…. & implement the feature and write the test…. & implement the feature and write the test…. ..... feature을 구현하고 test를 작성하고… 를 계속 반복하는 것이 유닛 테스팅이다 [ 2 ] 간단한 예제 - Calculator class Calculator { func add(_ a: Int, _ b: Int) -> Int { return a + b } func subtract(_ a: Int, _ b: Int) -> Int { return a - b } } Calculator에 구현한 더하기 빼기 기능이 잘못된 ..
- Total
- Today
- Yesterday
- 플러터 싱글톤
- 플러터 얼럿
- Dart Factory
- Flutter Spacer
- PencilKit
- 장고 Custom Management Command
- SerializerMethodField
- Watch App for iOS App vs Watch App
- flutter 앱 출시
- 장고 URL querystring
- Python Type Hint
- Flutter 로딩
- Django FCM
- github actions
- flutter build mode
- flutter dynamic link
- Sketch 누끼
- 구글 Geocoding API
- Flutter getter setter
- Django Firebase Cloud Messaging
- ipad multitasking
- Flutter Clipboard
- ribs
- cocoapod
- Flutter Text Gradient
- Django Heroku Scheduler
- METAL
- DRF APIException
- flutter deep link
- drf custom error
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |