-
SwiftUI UIKit 71 - UIKit앱에 SwiftUI 적용하기SwiftUI 100 레시피/UIKit and SwiftUI Interoperability 2022. 6. 28. 15:50
#1. Storyboard로 프로젝트 생성
#2. Info.pilist에서 Main 삭제
#3. Storyboard Name key 삭제
삭제전 삭제후 #4. RatingView 끌어와서 폴더에 삽입
RatingView swfitUI 화일 끌어와서 삽입 #5. MovieListScreen SwiftUI화일 생성
import SwiftUI
struct MovieListScreen: View {
var body: some View {
List(1...20, id: \.self){ index in
HStack {
Text("Movie \(index)")
Spacer()
RatingView(rating: .constant(Int.random(in: 1...5)))
}
}
}
}
struct MovieListScreen_Previews: PreviewProvider {
static var previews: some View {
MovieListScreen()
}
}
#6. SceneDelegate 수정
import UIKit
import SwiftUI //추가
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
//수정전
//guard let _ = (scene as? UIWindowScene) else { return }
// 수정후
guard let windowScene = (scene as? UIWindowScene) else { return }
let window = UIWindow(windowScene: windowScene)
window.rootViewController = UIHostingController(rootView: MovieListScreen())
window.makeKeyAndVisible()
self.window = window
}
'SwiftUI 100 레시피 > UIKit and SwiftUI Interoperability' 카테고리의 다른 글
SwiftUI UIKit 72 - SwiftU에서 UIKit 뷰로 데이터 전송 (0) 2022.06.28 SwiftUI UIKit 69 - SwiftUI에서 UIActivityIndicatorView 로딩 구현 (0) 2022.06.28