KeyPath 를 SwiftUI 쪽에서 자주 쓰면서 Swift 코드에도 자주 사용하고 싶어서 정리 및 useful example 을 모아두려고 한다. 사실.. 예를들어 map(\.xx) 이런 코드 많이 축약됐네~ 이런 느낌도 잘안들고 익숙하지도 않아서 잘안썼는데 앞으로는 의도적으로 더 많이 써보고 싶음. [참고자료] - Swift Docs > Key-Path Expressions - KeyPath 구현 [1] Key Path 정리 1. 백슬래쉬를 쓰는 이런 Key-Path Expression 은 컴파일 타임에 KeyPath class 의 instance 로 교체된다. \. 2. 모든 타입에 subscript(keyPath:) 가 구현되어있다. 이 서브스크립트에 keypath 를 넘기며 사용하면 된다. s..
Collection 문서를 보면 Time Complexity 가 두개로 나온 부분이 많은데요, 예를들어 1) randomElement() 2) distance(from:to:) 3) count ✓ RandomAccessCollection = 효율적인 random-access index 순회를 지원하는 콜렉션 ✓ BidirectionalCollection = 양방향 (forward, backward) 순회를 지원하는 콜렉션 이렇게 두개의 콜렉션이 있는데, Expected Performance 에 잘 나와있는 것 처럼 bidirectional collection 는 전체 collection 을 순회해서 카운팅 해야하므로 O(1) 의 시간복잡도를 가질 수 없기 때문입니다. 각 콜렉션 문서에서도 차이를 잘 볼 ..
과거에 Continuations 를 이용해서 짰던 코드를 보는데 헷갈렸다.. @)@ 리마인드가 필요하군 우선 요 목차(?)가 머릿 속에 있어야한다. [1] 용어 기억 가끔 용어도 잘 생각이 안날 때가 있다,, [ Continuation ] 비동기 코드를 래핑해서 연속(continuation)을 만든다! 라고 기억하자 문서에서는 이렇게 표현한다. To create a continuation in asynchronous code, call the withUnsafeContinuation(function:_:) or withUnsafeThrowingContinuation(function:_:) function. [ CheckedContinuation vs UnsafeContinuation ] 잘 까먹는 주요원..
# self in a clousre 다음과 같은 경우 Strong Reference Cycle (Retain Cycle) 이 발생한다. class SomeViewController: UIViewController { var someClosure: (() -> Void)? deinit { print("deinit") } override func viewDidLoad() { super.viewDidLoad() self.someClosure = { print(self) } } } 그래서 클로져 캡쳐리스트를 작성한다. class SomeViewController: UIViewController { var someClosure: (() -> Void)? deinit { print("deinit") } overri..
Swift-Collections 패키지가 나오고 다른 언어에는 있지만 Swift 에는 없어서 직접 구현해야했던 자료구조들 (deque, heap..) 이 제공되고 있다. [Swift Collections] deque 에 이어서 heap 을 살펴보자. 마찬가지로 이미 해당 자료구조를 내장 모듈로 제공하던 python 과 함께 살펴보자. [1] python 의 heap python은 heap 과 PriorityQueue (heap을 통해 구현) 를 모두 제공한다. # heap ✓ 파이썬의 heap은 min heap 이다. (min heap = 모든 부모 노드가 자식보다 작거나 같은 값을 갖는 이진 트리) ✓ 즉 모든 k에 대해 heap[k]
문서를 보면 Dictionary 의 subscript 로 세개가 구현되어있다. ✓ subscript(Key) -> Value? // get set ✓ subscript(Key, default _: () -> Value) -> Value // get set ✓ subscript(Dictionary.Index) -> Dictionary.Element // get 3번째처럼 key-based subscript 가 아니라 index-based subscript 도 있는 줄 몰랐는데, 정리해두자! [1] subscript(Key) -> Value? - 문서 - 코드 구현 var responseMessages = [200: "OK", 403: "Access forbidden", 404: "File not found..
[ 이 글에서 다루는 내용 ] - actor 의 등장배경 - actor - nonisolated - global actor - main actor [1] actor 가 나오기 전에는? 예전에는 data race가 발생할 수 있다면 lock 이나 queue 를 추가 구현해줘야했다. 대충 data race 가 발생할 수 있는 상황을 만들고, Thread Sanitizer 를 켜고 돌려보자. class UserManager { static let shared = UserManager() private(set) var userName = "" private init() {} func updateUserName(to name: String) { print(Thread.current) userName = name ..
Sendable 문서와 WWDC 22 > Eliminate data races using Swift Concurrency 를 조합해서 재구성한 내용입니다. [1] Sendable = safe to share Sendable 프로토콜은 concurrencey 상황에서 안전하게 공유될 수 있는 타입을 나타냅니다. 즉 우리는 하나의 concurrency domain (또는 isolation domain)에서 다른 domain으로 sendable type을 안전하게 pass 할 수 있습니다. (data race를 만들지 않고) [2] Sendable 을 채택할 수 있는 타입 1. Value Types frozen struct or enumeration. 아래 사진에 나오는 Chicken 은 class인데 이를 ..
[1] TaskGroup과 ThrowingTaskGroup ✓ TaskGroup : A group that contains dynamically created child tasks. (자세한 설명은 이 글 5번 참고) taskGroup을 만드려면 withTaskGroup(of:returning:body:) 를 호출. ✓ ThrowingTaskGroup : A group that contains throwing, dynamically created child tasks. throwing task group을 만드려면 withThrowingTaskGroup(of:returning:body:) 를 호출 [2] 사용예제 2.1 간단한 병렬 실행을 위해 async-let syntax 를 쓰다가 확장이 필요할 때 ..
WWDC 2016 Understanding Swift Performance 를 보다가 명확히 몰랐던 세가지를 알게 되었다. 1️⃣ final 키워드를 붙이면 컴파일이 빨라진다고 알고 있는데 이유가 뭘까? 2️⃣ uuid 필드를 String 타입 vs UUID 타입으로 들고 있는 것 중에 뭐가 더 좋은걸까? 3️⃣ 프로토콜과 달리 제네릭을 쓸 때는 구체타입을 왜 못바꿀까? [1] final 키워드 --- WWDC 세션 중 Method Dispatch 부분에 나오는 내용 ---- ✓ static dispatch: 컴파일 타임에 어떤 구현이 실행될 건지 알 수 있음 ✓ dynamic dispatch: 런타임에 어떤 구현이 실행될 건지 알 수 있음 static dispatch 인 경우, 컴파일러는 여러 기법 (..
- Total
- Today
- Yesterday
- METAL
- 구글 Geocoding API
- PencilKit
- Flutter Clipboard
- Dart Factory
- flutter dynamic link
- cocoapod
- 플러터 싱글톤
- SerializerMethodField
- 장고 Custom Management Command
- drf custom error
- DRF APIException
- Flutter Spacer
- ipad multitasking
- flutter build mode
- flutter 앱 출시
- Django Firebase Cloud Messaging
- Django Heroku Scheduler
- Watch App for iOS App vs Watch App
- 플러터 얼럿
- 장고 URL querystring
- Flutter getter setter
- flutter deep link
- Django FCM
- Sketch 누끼
- ribs
- github actions
- Python Type Hint
- Flutter Text Gradient
- Flutter 로딩
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
31 |