iOS When use the '$'?

운영 체제: macOS Monterey 12.3.1
사용 버전: Xcode 13.3, SwiftUI

iOS When use the '$'를 알아보겠습니다.


SwiftUI '$' 표시는 Struct의 데이터를 다른 Struct에서 변경할 때 사용합니다.
간단한 예로 TextField가 있습니다.
TextField 문서를 보면 Binding을 입력하는 값이 있습니다.
이 Binding을 표시해주는게 $ 입니다.





아래와 같이 myTexInput을 변경할 수 있게 @State 선언을 해주고 이 변수를 TextField 두 번째 인자로 넣었습니다. 오류가 나네요.






오류의 내용은 다음과 같습니다.

Cannot convert value 'myTextInput' of type 'String' to expected type 'Binding<String>', use wrapper instead

insert '$'






$표시를 해줌으로써, TextField에서 myTextInput의 값을 자유롭게 변경 할 수 있게 만들어 줍니다.






끝.


카테고리: iOS

댓글

이 블로그의 인기 게시물

Python urllib.parse.quote()

KiCad 시작하기 4 (기존 회로도 수정 및 추가)

Android Compose Coil library

KiCad 시작하기 1 (회로도 만들기)

Android Notification with Full Screen

iOS Swift callAsFunction

Android Custom IME(Input method editor) 만들기

iOS Error Undefined symbol Testing.Trait

Android Compose automation for getting localized images to use on Play Store app image

tensorflow tf.expand_dims()