Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- combine
- github
- concurrency
- SWIFT
- swiftdata
- iOS 개발자
- xcode
- regex
- Tuist
- Firebase
- Alamofire
- uikit
- Git
- SWIFTUI
- test
- ios18
- network
- Navigation
- navigationsplitview
- tuist #xcodecloud #ios #ci/cd #swiftlint #firebase
- 정규표현식
- xcodecloud
- composablearchitecture
- iOS 13.0+
- TCA
- 모바일
- IOS
- UI
- ObjC
- 개발
Archives
- Today
- Total
iOS 개발 기록
[iOS] swiftUI에서 UIKit 사용하기 본문
728x90
UIKit에서 가져오기
Date: 2023년 1월 3일
Tags: SwiftUI, UIKit, iOS 13.0+
UIViewRepresentable
struct NuguView: UIViewRepresentable {
// UIViewRepresentable 구성을 위한 코드
}
- UIView를 SwiftUI에서 사용하기 위해 지원되는 프로토콜
- makeUIView(context:)와 updateUIVIew(_: context:) 메소드를 필수로 구현해야 한다.
makeUIView(context:)
func makeUIView(context: Context) -> NuguUIView {
return nuguView
}
- Context를 가지고 View의 초기 상태 인스턴스를 만든다. 간단하게 ViewDidLoad와 비슷하게 생각해도 될듯.
updateUIVIew(_: context:)
func updateUIView(_ uiView: NuguUIView, context: Context) {
nuguView.voiceChromePresenter.delegate = context.coordinator
nuguView.displayWebViewPresenter.delegate = context.coordinator
nuguView.audioDisplayViewPresenter.delegate = context.coordinator
}
- view의 상태를 변경할 때 마다 SwiftUI에 의해 자동으로 호출되는 메소드
makeCoordinator()
func makeCoordinator() -> Coordinator {
return Coordinator(nuguView: nuguView)
}
class Coordinator: NSObject, VoiceChromePresenterDelegate, DisplayWebViewPresenterDelegate, AudioDisplayViewPresenterDelegate {
// 각종 Delegate 메소드 구현
...
}
- UIKit의 view가 다른 부분과 데이터를 주고 받을 때 (Delegate 등…) 이를 연결하기 위한 메소드.
- context로 Coordinator 인스턴스에 접근하여 delegate를 할당한다. → updateUIView
사용
VStack {
Text("예제!")
NuguView()
}
- SwiftUI의 일반 View를 사용하듯 쓰면 된디ㅏ.
UIViewControllerRepresentable
- UIView와 마찬가지로 동일하게 사용
참고
Using UIView and UIViewController in SwiftUI
'SwiftUI' 카테고리의 다른 글
[SwiftUI]데이터 바인딩 (0) | 2023.03.03 |
---|---|
[iOS] WidgetKit (0) | 2023.02.06 |
SwiftUI - View의 크기를 구하는 방법 (0) | 2022.07.07 |
SwiftUI - Realm (0) | 2022.04.26 |
SwiftUI - 애니메이션 (0) | 2022.04.21 |