보호되어 있는 글입니다.
☑️ dynamic-callable 간단 설명 @dynamicCallable 은 객체가 함수처럼 동작할 수 있도록 만들어준다. 쉽게 말하면, 해당 객체에 대해 함수 호출 연산자 ()를 사용할 수 있게 해준다. 이를 통해 동적으로 호출되는 동작을 구현할 수 있다.어떤 객체의 호출을 일반화하거나, 다양한 유형의 인자를 처리하는 등의 상황에서 유용하다. [1] 수학연산 @dynamicCallablestruct DynamicMultiplier { func dynamicallyCall(withArguments args: [Int]) -> Int { return args.reduce(1, *) }}let multiplier = DynamicMultiplier()multiplier(1,..
![](http://i1.daumcdn.net/thumb/C148x148/?fname=https://blog.kakaocdn.net/dn/ZIMHi/btsyTn2y5Ew/0Ivrhvy5pVPTqVQrvy4k0K/img.png)
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인데 이를 ..
- Total
- Today
- Yesterday
- flutter deep link
- Watch App for iOS App vs Watch App
- SerializerMethodField
- 플러터 싱글톤
- Django Heroku Scheduler
- drf custom error
- Python Type Hint
- flutter dynamic link
- Flutter 로딩
- 장고 Custom Management Command
- Flutter Spacer
- Flutter Text Gradient
- flutter build mode
- METAL
- Django FCM
- ipad multitasking
- cocoapod
- Dart Factory
- Flutter getter setter
- ribs
- PencilKit
- 구글 Geocoding API
- Sketch 누끼
- flutter 앱 출시
- github actions
- Flutter Clipboard
- Django Firebase Cloud Messaging
- 플러터 얼럿
- 장고 URL querystring
- DRF APIException
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |