일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 스위프트
- map
- 클린 코드
- UITextView
- combine
- collectionview
- RxCocoa
- tableView
- ribs
- ios
- Xcode
- Clean Code
- HIG
- Human interface guide
- swift documentation
- UICollectionView
- uiscrollview
- Observable
- swiftUI
- MVVM
- uitableview
- 리팩토링
- 리펙터링
- Refactoring
- SWIFT
- Protocol
- clean architecture
- rxswift
- 리펙토링
- 애니메이션
- Today
- Total
목록2022/11 (30)
김종권의 iOS 앱 개발 알아가기
목차) Combine - 목차 링크 Combining 연산자 * 스트림에서 방출되는 2개 이상의 요소들을 묶어서 방출하는 방법 예제에 사용할 스트림 2개 준비) PassthroughSubject는 downstream subscribers에게 값을 broadcast하는 subject 값을 저장하고 있지는 않고 단순히 값을 토스 해주는 역할 RxSwift의 PublishSubject와 동일 (구체적인 개념은 이전 포스팅 글 참고) let passthroughSubject1 = PassthroughSubject() let passthroughSubject2 = PassthroughSubject() combineLatest(_:_:) 두 스트림 모두 메시지를 받았을때 이벤트 방출 해당 연산자에서 이전 값을 기억..
목차) Combine - 목차 링크 Selecting 연산자 * Combine에서 제공하는 Selecting 연산자는 기존 Swift에서 제공하는 연산자의 인터페이스와 동일하게 설계되어 사용하기 쉽도록 구현 first() [1,2,3,4,5].publisher .first() .sink { print($0) } // 1 last() [1,2,3,4,5].publisher .last() .sink { print($0) } // 5 tryFirst 조건에 해당하는 firrst를 만나기 전까지 throw가 발생 안하면 에러 x struct SomeError: Error {} [1,2,3,4,5].publisher .tryFirst(where: { guard $0 != 3 else { throw SomeErro..
목차) Combine - 목차 링크 Matchging 연산자 * Combine에서 제공하는 Matching 연산자는 기존 Swift에서 제공하는 연산자의 인터페이스와 동일하게 설계되어 사용하기 쉽도록 구현 contains(where:) where 클로저 조건에 따라 Bool 반환 [1,2,3,4,5].publisher .contains(where: { $0 == 3 }) .sink { print($0) } // true tryContains(where:) contains는 true를 반환하면 이후 값에 관해서 체크하지 않음을 주의 (아래에서 true를 먼저 반환하므로 throw 발생 x) [1,2,3,4,5].publisher .tryContains(where: { guard $0 != 5 else { ..
목차) Combine - 목차 링크 Sequence 연산자 drop(while:) 일반 while (condition) { body } 과 동일 while 안에 조건이 true일때만 값을 drop [1,3,5,7,8,9]가 있을때 1, 3, 5, 7 까지 계속 홀수이므로 while문 내부가 true이므로 모두 drop 8에서 while문이 false이므로 while문이 break while문이 break되었으므로 9는 방출 [1,3,5,7,8,9].publisher .drop(while: { $0 % 2 != 0 }) .sink { print($0, terminator: " ") } // 8 9 dropFirst() 첫번째 요소만 drop [1,2,3,4,5].publisher .dropFirst() ...
목차) Combine - 목차 링크 Math 연산자 .count() 의미 그대로 배열의 갯수를 반환 max(by:) by에 해당하는 조건을 갖는 최댓값 반환 [(1, 2), (1, 3), (1, 4)].publisher .max(by: { $0.1 < $1.1 }) .sink { print($0) } // (1, 4) tryMax() throw를 던질 수 있는 max 연산자 struct MinusError: Error {} [1,2,-1,3,4].publisher .tryMax { first, second in // first, second = (1, 2), (2, -1), (-1,3), ... guard first != -1, second != -1 else { throw MinusError.init(..
목차) Combine - 목차 링크 Reduce 배열과 같은 Sequence형태를 하나의 값이나 축소 시키는 연산자 collect 연산자 collect(n)이면 n 만큼 묶어서 방출 (0...10).publisher .collect(5) .sink { print($0) } /* [0, 1, 2, 3, 4] [5, 6, 7, 8, 9] [10] */ ignoreOutput() 값이 방출되는 값은 모두 무시하고 completion의 failure만 방출 struct NoZeroValuesAllowedError: Error {} let numbers = [1, 2, 3, 4, 5, 0, 6, 7, 8, 9] numbers.publisher .tryFilter({ anInt in guard anInt != 0 ..
목차) Combine - 목차 링크 Filtering 연산자 filter // filter [1,2,3].publisher .filter { $0 % 2 == 0 } .sink(receiveValue: { print($0) }) .store(in: &cancellable) // 2 tryFilter 특정 조건에 해당하면 Error를 throw throw를 처리하는 곳은 .sink의 receiveCompletion에서 수행 주의할점은 throw가 발생하면 해당 스트림은 해제되기 때문에 3은 방출되지 않음 [1,2,-1,3].publisher .tryFilter { if $0 == -1 { throw MyError.a } else { return true } } .sink( receiveCompletion..
목차) SwiftUI의 기본 - 목차 링크 trim(from:to:) trim: 불필요한 부분을 잘라내는 것 trim(from:to:) - from과 to 파라미터에 들어가는 값은 0에서 1의 값 이전 포스팅에서 알아본 SwiftUI의 Path로 만들어진 부분에 trim을 적용하여 사용 Path로 만들어진 것들 -> Shape 프로토콜을 준수하고 있는 형태에 모두 적용 가능 from에는 Path의 시작점이 들어가고, to는 Path의 남겨질 부분의 끝점이 들어가며, 이 점들을 잇는 도형으로 표현 주의: trim이지만, from과 to에 들어가는 부분을 잘라내는게 아닌 그 부분을 살려내는 것 ex) Circle은 Shape 프로토콜을 준수하고 있어서 (= Path로 그러진 형태), trim 사용이 가능 (..