본문 바로가기

iOS

UIBackgroundTaskIdentifier A unique token that identifiers a request to run in the background백그라운드에서 실행할 요청을 식별하는 고유 토큰Identifierstatic let invalid: UIBackgroundTaskIdentifierA token that indicates an invalid task request작업 요청을 invalid 시키는 것을 나타내는 토큰예제import UIKitclass CounterTimer { private var countdownValue = 180 let counterPublisher: PassthroughSubject = .init() private var cancellables: Set = [] .. 더보기
UnsafePointer A pointer for accessing data of a specific typeUnsafePointer provides no automated memory management or alignment guarantees.You are responsible for handling the life cycle of any memory you work with through unsafe pointers to avoid leaks or undefined behaviorwithUnsafePointer(to) { pointer _ }Invokes the given closure with a pointer to the given argument주어진 변수를 클로저 안에서 포인터로 바꾸어 사용하도록 해주는 함수포인터.. 더보기
NWPathMonitor An observer that you use to monitor and react to network changes.네트워크 변화를 감지해 전달해주는 클래스iOS 14부터 사용 가능Creating Path Monitorsfunc start(queue: DispatchQueue)Starts monitoring path changes, and sets a queue on which to deliver path events모니터를 시작하는 함수var queue: DispatchQueue?The Queue on which path events are deliveredpath events를 전달하기 위한 큐Handling Path Updatesvar currentPath: NWPathThe currently av.. 더보기
UnsafePointer A pointer for accessing data of a specific typeUnsafePointer provides no automated memory management or alignment guarantees.You are responsible for handling the life cycle of any memory you work with through unsafe pointers to avoid leaks or undefined behaviorwithUnsafePointer(to) { pointer _ }Invokes the given closure with a pointer to the given argument주어진 변수를 클로저 안에서 포인터로 바꾸어 사용하도록 해주는 함수포인터.. 더보기
Zip Combines elements from two other publishers and delivers groups of elements as tuples. 다른 두 퍼블리셔로 부터 값을 묶어서 튜플형태로 방출한다(단, zip은 각 퍼블리셔들의 값이 동일할 때만 묶어 방출한다) zip.sink(receiveValue: { result in print("zip: \\(result.0), \\(result.1)") }) .store(in: &cancellables) left.send("Left") right.send("Right") right.send("Right2") left.send("Left2") // 결과값 zip: Left, Right zip: Left2, Right2 combineLatest와 마찬.. 더보기
CombineLatest Subscribes to an additional publisher and publishes a tuple upon receiving output from either publisher. 추가의 퍼블리셔 를 연결하여 Tuple 형태로 묶어서 값을 방출하는 연산자 var cancellables: Set = [] let left = PassthroughSubject() let right = PassthroughSubject() let combineLatest = Publishers.CombineLatest(left, right) combineLatest.sink(receiveValue: { result in print("combineLatest: \\(result.0), \\(result.1)") }) .s.. 더보기
WithLatestFrom Combines the source Observable with other Observables to create an Observable whose values are calculated from the latest values of each, only when the source emits AObservable.withLatestFrom(BObservable) 일 경우 A,B Source(A)값이 방출될때마다 A,B의 최신값을 묶어서 방출하는 오퍼레이터. A,B가 모두 방출 된 상태에서만 A 방출 시 값이 방출되며, Source가 아닌 B는 최신값만 트래킹하며 값을 방출하는 이벤트는 없다. 즉, A,B모두 방출되었고, A 방출 이벤트가 발생하면 A,B의 최신 값을 묶어서 방출한다. inputs.num.. 더보기
Singleton Pattern 싱글턴 이란 싱글턴은 클래스에 인스턴스가 하나만 있도록 하면서, 이 인스턴스에 대한 전역 접근(액세스) 지점을 제공하는 디자인 패턴이다. 문제 싱글턴 패턴은 한 번에 두 가지의 문제를 동시에 해결함으로써 단일 책임 원칙을 위반한다. 클래에 인스턴스가 하나만 있도록 한다. 사람들은 클래스에 있는 인스턴스 수를 제어하려는 가장 일반적인 이유는 일부 공유 이소스에 대한 접근을 제어하기 위함이다. 생성자 호출은 반드시 새 객체를 반환해야 하므로 위 행동은 일반 생성자로 구현할 수 없다. 해당 인스턴스에 대한 전역 접근 지점을 제공한다. 전역 변수들을 사용하면 편의성은 올라가지만, 모든 코드가 잠재적으로 해당 변수의 내용을 덮어쓸 수 있고 그로 인해 앱에 오류가 발생해 충돌할 수 있어 안정적이지 않다. 싱글턴 패.. 더보기