SwiftUI/Basic Property Wrappers
-
PassthroughSubject VS CurrentValueSubjectSwiftUI/Basic Property Wrappers 2021. 12. 10. 19:29
PassthroughSubject A subject that broadcasts elements to downstream subscribers. Declaration final class PassthroughSubject whereFailure : Error Overview As a concrete implementation of Subject, the PassthroughSubject provides a convenient way to adapt existing imperative code to the Combine model. Unlike CurrentValueSubject, a PassthroughSubject doesn’t have an initial value or a buffer of the ..
-
-
SwiftUI ) StateObject Apple Documentation 번역SwiftUI/Basic Property Wrappers 2021. 10. 5. 19:44
StateObject Observable Object 의 instance 를 만들 때 사용하는 Property Wrapper ( iOS 14 이상에서만 가능.. 아마도 SwiftUI 2.0 이상?) Observed Object ( Binding Object 라고 생각하면 편해요. (State Binding 은 두 views 사이에서만! ) class도 Object가 될 수 있음. 단, ObservableObject를 conform해야함. (class CustomClass: ObservableObject) class 라서 여러 properties, methods 를 가질 수 있고, 각 properties 는 선택적으로 @Published wrapper 를 씌울 수 있음. 이게 씌인 것들은 변할 때마다 vi..
-
SwiftUI) State, ObservedObject, StateObject, and EnvironmentObject보호글 2021. 9. 13. 18:42
보호되어 있는 글입니다.
-
SwiftUI) State, Binding wrapperSwiftUI/Basic Property Wrappers 2021. 9. 13. 17:02
SwiftUI 로 개발을 하다보면 다음과 같은 Property Wrapper 가 아주 많이 보이게 되는데, 이번 포스트에서는 매우매우 빈번히 쓰이는 wrapper 중에서 @State, @Bind 대해서 알아보도록 하겠습니다. @State SwiftUI 에서 View 들은 Struct 이고, Struct 는 value type 으로, 값을 바꾸는게 허용되지 않아요 .. SwiftUI 에서는 값들을 바꿀 수 있게 해주기 위해 @State property Wrapper 를 제공합니다. struct ContentView: View { var testString = "" var body: some View { Button(action: { // testString = "asd" Cannot assign to pr..
-
SwiftUI) Binding, presentationMode (Two ways to dismiss view)SwiftUI/Basic Property Wrappers 2021. 9. 13. 14:10
어떤 프로젝트를 보다가, 다음과 같은 코드를 보고 열심히 찾아보았다. @Environment(\.presentationMode) var presentationMode 결론부터 말하면, SwiftUI 에서 sheet 를 이용할 때 dismiss 하는 방법 중 하나로 많이 쓰이는 방법이고, 보통 두가지 방법이 쓰인다. ( presentationMode, Binding ) 1. presentationMode 이용하기. 해당 sheet 에서 'presentation mode environment key' 를 이용하여 스스로를 dismiss 하라고 시키는 방법이다. 어떠한 view 에서도 presentation mode 를 @Environment(\.presentationMode) 를 이용해 읽을 수 있고, wr..