iOS/Combine

    [Combine] Chapter 17: Schedulers

    Operators for scheduling 2가지 기본 operator가 있음 subscribe(on:) subscribe(on:options:) create 특정 스케줄러 위에서 subscription을 만들어줌. subscription에 대한 설명이 좋은데 start the work 이라 되어 있음. receive(on:) receive(on:options) delivers 특정 스케줄러 위에서 value를 전달해줌. 챕터6 Time Manipulation Operators에서도 배운 것들 debounce(for:scheduler:options:) delay(fortolerance:scheduler:options:) measureInterval(using:options:) throttle(for:s..

    [Combine] Chapter 16: Error Handling

    이번 챕터에서는 에러 핸들링에 대해 알아보겠습니다. 비동기 이벤트를 다룰 때 에러가 항상 발생할 수 있습니다. 그래서 에러를 다루는 기술을 굉장히 중요합니다. Publisher Failure 이 친구에 집중해봅시다. Never publisher가 fail 이벤트가 절대 일어나지 않는 경우 사용합니다. 예를들어 Just를 확인해보면 Failure가 Never로 정의된 것을 볼 수 있습니다. setFailureType infallilbe publisher 를 만드는 방법! assign(to:on:) assign 이 걸려있는 곳에서 setFailureType을 하려고 하면 컴파일이 되지 않습니다. Failure가 Never 일때만 assign이 가능한것으로 보입니다. assertNoFailure 에러가 발생헀..

    [Combine 책 정리] Chapter 13: Resource Management

    안녕하세요 코찐입니다. 아래의 자료를 따라서 공부하고 있습니다. https://www.raywenderlich.com/books/combine-asynchronous-programming-with-swift/v2.0 리소스 관리하는 Publisher 들인데, API 작업할 때 유용하게 사용할 수 있습니다. share value 타입이 아닌 reference 타입의 publisher를 공유할 수 있도록 해줍니다. 주의할 점은 이미 complete 된 share publisher를 구독하면 complete만 받게 됩니다. let shared = URLSession.shared .dataTaskPublisher(for: URL(string: "https://www.raywenderlich.com")!) .ma..

    [Combine 책 정리] Chapter 12: Key-Value Observing

    안녕하세요 코찐입니다. 아래의 자료를 따라서 공부하고 있습니다. https://www.raywenderlich.com/books/combine-asynchronous-programming-with-swift/v2.0 KVO 그 유명한 KVO 입니다. OperationQueue의 operation 개수가 변경되면 sink에서 이벤트를 받아볼 수 있습니다. let queue = OperationQueue() let subscription = queue.publisher(for: \.operationCount) .sink { print("Outstanding operations in queue: \($0)") } 커스텀으로 만들려면? 1. NSObject 상속 2. @objc dynamic 키워드 KVO가 O..

    [Combine 책 정리] Chapter 11: Timers

    안녕하세요 코찐입니다. 아래의 자료를 따라서 공부하고 있습니다. https://www.raywenderlich.com/books/combine-asynchronous-programming-with-swift/v2.0 타이머 클래스에는 삼형제가 있습니다. RunLoop, Timer, DispatchQueue RunLoop 특정 RunLoop 상에서 이벤트를 발생시킬 수 있습니다. 1초마다 한번씩 print 합니다. let runLoop = RunLoop.main runLoop.schedule( after: runLoop.now, interval: .seconds(1), tolerance: .milliseconds(100) ) { print("Timer fired") }.store(in: &subscript..

    [Combine 책 정리] Chapter 10: Debugging

    안녕하세요 코찐입니다. 아래의 자료를 따라서 공부하고 있습니다. https://www.raywenderlich.com/books/combine-asynchronous-programming-with-swift/v2.0 let subscription = (1...3).publisher .print("publisher") .sink { _ in } // 다음에서 발췌: By Marin Todorov. ‘Combine: Asynchronous Programming with Swift.’ Apple Books. publisher: receive subscription: (1...3) publisher: request unlimited publisher: receive value: (1) publisher: rec..

    [Combine 책 정리] Chapter 9: Networking

    안녕하세요 코찐입니다. 아래의 자료를 따라서 공부하고 있습니다. https://www.raywenderlich.com/books/combine-asynchronous-programming-with-swift/v2.0 한 가지 API Publisher에 여러 Subscriber가 붙는 예제입니다. let url = URL(string: "https://www.raywenderlich.com")! let publisher = URLSession.shared .dataTaskPublisher(for: url) .map(\.data) .multicast { PassthroughSubject() } let subscription1 = publisher .sink(receiveCompletion: { complet..

    [Combine 책 정리] Chapter 7: Sequence Operators

    안녕하세요 코찐입니다. 아래의 자료를 따라서 공부하고 있습니다. https://www.raywenderlich.com/books/combine-asynchronous-programming-with-swift/v2.0 Finding values min greedy: publisher가 finsih될 때 까지 기다림 [1, -50, 246, 0].publisher.min() // -50 value가 Comparable을 준수하지 않는다면? Comparable을 준수하지 않는 객체가 있으면 비교문을 직접 넣어서 min을 사용할 수 있다. 아래 예제에서는 억지로 Comparable을 준수하지 않도록 만든 다음 min을 찾도록 해보는 것. 조금 억지지만 이렇게 하면 결과값에서 다시 String으로 변환해서 체크해..