본문 바로가기

분류 전체보기148

NSOpenPanel, NSSavePanel 예제 안녕하세요 ◠‿◠ 고고입니다. NSOpenPanel과 NSSavePanel로 png, jpeg 등 이미지를 열고 저장하는 것과 pdf, hwp 등의 파일을 열고 저장하는 코드를 올려봤습니다. 편하게 사용해주세요~ 1. NSOpenPanel 1.1 Open images extension NSOpenPanel { // Image 가져오기 실패 시 사용 enum ImageError: Error { case selectionFailed } static func openImage(completion: @escaping (_ result: Result) -> Void) { let panel = NSOpenPanel() // 다중 선택가능 panel.allowsMultipleSelection = false // 파일.. 2021. 11. 25.
[SwiftUI] `ForEach(_:content:)` should only be used for *constant* data. === AttributeGraph: cycle detected through attribute 697368 === ForEach count (8) != its initial count (7). `ForEach(_:content:)` should only be used for *constant* data. Instead conform data to `Identifiable` or use `ForEach(_:id:content:)` and provide an explicit `id`! 안녕하세요 ◠‿◠ 고고입니다. 갑자기 저 위의 문구가 한 20개쯤은 떠서 당황했는데 읽어보면 ForEach를 할 때 idenfiable을 상속하는 데이터를 쓰거나 id를 넣어달란 뜻이었습니다. 따라서 다음과 같이 고쳤습니다. .. 2021. 11. 25.
[RxSwift] Operators - 오류 처리(5) Observable이 던진 오류를 복구할 수 있도록 도와주는 연산자들 - Catch, Retry 안녕하세요 ◠‿◠ 고고입니다. 1. Catch Catch — 오류를 무시하고 배출되는 항목들을 계속 진행시켜 'onError'로부터 전달된 오류를 복구한다 구현부 public func `catch`(_ handler: @escaping (Swift.Error) throws -> Observable) -> Observable { Catch(source: self.asObservable(), handler: handler) } 예시 let source = Observable.create { observer in for count in 1...3 { observer.on(.next(count)) } let erro.. 2021. 11. 20.
[RxSwift] Operators - 결합(4) 여러 개의 소스 Observable들을 하나의 Observable로 만드는 연산자들 - CombineLatest, merge, startwith, switch, zip, withLatestFrom, concat 안녕하세요 ◠‿◠ 고고입니다. 1. CombineLatest CombineLatest — 두 개의 Observable 중 하나가 항목을 배출할 때 배출된 마지막 항목과 다른 한 Observable이 배출한 항목을 결합한 후 함수를 적용하여 실행 후 실행된 결과를 배출한다 구현부 public static func combineLatest (_ source1: O1, _ source2: O2, resultSelector: @escaping (O1.Element, O2.Element) throws ->.. 2021. 11. 20.
[RxSwift] Operators - 필터링(3) 소스 Observable에서 선택적으로 항목을 배출하는 연산자들 - Debounce, Distinct, ElementAt, Filter, First, IgnoreElements, Sample, Skip, Take 안녕하세요 ◠‿◠ 고고입니다. 1. Debounce Debounce — Observable의 시간 흐름이 지속되는 상태에서 다른 항목들은 배출하지 않고 특정 시간 마다 그 시점에 존재하는 항목 하나를 Observable로부터 배출한다 구현부 public func debounce(_ dueTime: RxTimeInterval, scheduler: SchedulerType) -> Observable { return Debounce(source: self.asObservable(), dueTime: .. 2021. 11. 19.
Error: realm accessed from incorrect thread realm accessed from incorrect thread, cannot construct reference to unmanaged object, which can be passed across threads directly 안녕하세요 ◠‿◠ 고고입니다. 스택오버플로우를 보다보니 ‘you should never try to use let realm = try! Realm() to create a singleton Realm instance and than try to access that everywhere from your app.’ let realm = try! Realm() 저거를 하나로 두고 여러 개의 함수에서 불렀던 게 문제였습니다. ‘The best way to use Realm in .. 2021. 11. 19.