전체 글
-
[Swift] Actor (비동기 환경에서 Data Race 를 피해보자) - #1Swift 2023. 5. 6. 03:10
🤔 What and Why.. 회사에서 새로운 기능을 개발하면서 페이지 패칭과 로딩 스피너를 async/await 를 활용해서 구현했습니다. 빠르게 스크롤을 내리다보니 빠르게 페이지가 넘어가면 비동기적으로 패치가 불리게 되었고 그와중에 각종 변수의 값이 저의 예상과는 다르다는 것을 알게 되어서 공부의 필요성을 느끼게 되었습니다. 처음에는 NSLock, Semaphore 등을 공부해보려 했지만 Swift 의 최신 문법등과 잘 어울어질만한 Actor 을 공부하게 되었습니다. 🕴🏻 Actor? actor 는 class, enum, struct 과 같이 타입중 하나이며 참조 타입으로써 차이라면 동기적으로 상태에 접근한다는 것입니다. 이게 무슨 의미인지는 아래 코드에서 봅시다. 💻 Code 아래를 보시면 뭔가 기..
-
[SwiftUI] 화면에 구멍 뚫기 - .mask (iOS 15 부터)Swift/SwiftUI 2023. 5. 2. 23:13
struct ContentView: View { let colors: [Color] = [.red, .blue] var body: some View { LinearGradient(colors: colors, startPoint: .leading, endPoint: .trailing) .mask { Image(systemName: "flag.checkered") .font(.system(size: 128)) } .background(Color.blue.opacity(0.2)) .ignoresSafeArea() } }
-
[Swift] Protocol 을 처음 부터 공부해보자Swift 2023. 5. 2. 00:57
1. protocol 의 extension 에서 구현된 함수는 구조체 혹은 클래스에서 override 할수 없다. 2. extension 에서는 변수를 가지고 있을수 없다 (이건 protocol 뿐만은 아님) 3. protocol 의 변수는 property wrapper 로 감쌀수 없다 import Foundation protocol Fly { var altitude: CGFloat { get set } func cry() } extension Fly { mutating func fly() { altitude += 1.0 } } struct Bird: Fly { var altitude: CGFloat = 0.0 func cry() { print("howl") } } var bird = Bird() pri..
-
[SwiftUI] Preview 에서 Transition Animation 보기Swift/SwiftUI 2023. 4. 30. 00:24
struct ContentView_Previews: PreviewProvider { static var previews: some View { VStack { ContentView() } } } Previewing SwiftUI Transition Animations Being able to preview your transition animations right in Xcode will allow you to quickly make changes to get the perfect effect you're looking for. While updating SwiftUI Animations Mastery for iOS 15, I decided to take a deeper look into previewi..
-
[SwiftUI] onChange 는 같은 값이 재할당되어도 호출될까?Swift/SwiftUI 2023. 4. 29. 10:14
struct ContentView: View { @State var num = 0 var body: some View { VStack { Text("Tap me") .onTapGesture { didTapButton() } .onChange(of: num) { newValue in print(newValue) } } .padding() } func didTapButton() { num = 0 } } 안됨