
UIControl::show 메서드는 UIKit 프레임워크에서 제공하는 메서드입니다. SwiftUI 프로젝트에서 UIKit 프레임워크를 사용하려면 @UIAccessibilityConvertible 프로토콜을 구현하거나 UIKitView를 사용해야 합니다.
다음은 SwiftUI 프로젝트에서 UIControl::show 메서드를 사용하는 방법입니다.
#hostingforum.kr
swift
import SwiftUI
struct ContentView: View {
var body: some View {
Button(action: {
let alertController = UIAlertController(title: "알림", message: "알림 메시지", preferredStyle: .alert)
let action = UIAlertAction(title: "확인", style: .default)
alertController.addAction(action)
UIApplication.shared.keyWindow?.rootViewController?.present(alertController, animated: true)
}) {
Text("버튼")
}
}
}
위 코드에서는 UIAlertController를 생성하여 사용자에게 알림을 표시합니다. UIAlertController는 UIKit 프레임워크에서 제공하는 클래스입니다. SwiftUI 프로젝트에서 UIKit 프레임워크를 사용하려면 위와 같이 UIKitView를 사용하거나 @UIAccessibilityConvertible 프로토콜을 구현해야 합니다.
2025-07-26 21:59