iOS/SwiftUI

    [SwiftUI] @GestureState, @Namespace, @ScaledMetric

    @GestureState Gesture와 관련된 Wrapper다. struct SimpleLongPressGestureView: View { @GestureState var isDetectingLongPress = false var longPress: some Gesture { LongPressGesture(minimumDuration: 3) .updating(self.$isDetectingLongPress) { currentState, gestureState, transaction in gestureState = currentState } } var body: some View { Circle() .fill(self.isDetectingLongPress ? Color.red : Color.green) ..

    [SwiftUI] @UIApplicationDelegateAdaptor, @NSApplicationDelegateAdaptor

    UIKit의 AppDelegate와 SceneDelegate를 SwiftUI에 연결하는 방법이 있다. @UIApplicationDelegateAdaptor, @NSApplicationDelegateAdaptor UIApplicationDelegateAdaptor는 UIKit에서 많이 보던 AppDelegate 속성을 불러올 때 사용한다. class MyAppDelegate: NSObject, UIApplicationDelegate, ObservableObject { func application( _ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data ) { // Record the de..

    [SwiftUI] @Environment, @EnvironmentObject, @FocusedBinding, @FocusedValue

    @Environment 이름처럼 환경변수입니다. // 정해진 Key Path로 환경 변수를 컨트롤 할 수 있다. @Environment(\.colorScheme) var colorScheme: ColorScheme @Environment(\.horizontalSizeClass) var horizontalSizeClass 다크모드 등 환경에 대한 변수 설정이 가능하다 @EnvironmentObject 해당 Wrapper은 환경 객체로 ObservableObject Protocol를 따라야합니다. class ExampleEnvironmentObject: ObservableObject { @Published var attribute = "ExampleEnvironmentObject" } struct Secon..

    [SwiftUI] @Published, @ObservedObject, @StateObject

    2편에서는 @Published, @ObservedObject, @StateObject를 알아보자. @Published, @ObservedObject, @StateObject 세 가지 Wrapper는 관련이 깊어 한 번에 이해해보자. 먼저 ObservableObject Protocol을 알아야한다. ObservableObject은 객체 내 속성 값이 바뀔 때 호출되는 objectWillChange를 사용할 수 있게 된다. 여기서 @Published가 등장한다. @Published 속성이 변경되면, objectWillChange을 호출해준다. 해당 호출을 감시할 수 있도록 해주는 Wrapper가 @ObservedObject가 된다. class ExampleObservableObject: ObservableO..

    [SwiftUI] @State, @Binding, @AppStorage, @SceneStroage, @FetchRequest

    SwiftUI 에서 사용되는 Property Wrappers 를 정리해보자. @State SwiftUI 관련해서 강좌나 예제 코드를 보면 거의 처음 마주하는 키워드다. https://developer.apple.com/documentation/swiftui/state 변수 값이 바뀌면 변수와 연결된 View를 업데이트 한다. struct PlayButton: View { @State private var isPlaying: Bool = false var body: some View { Button(isPlaying ? "Pause" : "Play") { isPlaying.toggle() } } } RxSwift 의 Observe 기능을 한줄로 줄여버렸다. @Binding @State 변수를 자식 뷰로 전..