確認ダイアログ
confirmationDialogで破壊的な操作を選択できるようにします。
「確認ダイアログ」はCoddyKit上の無料SwiftUI Academyレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはSwiftUI Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 SwiftUI Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
What Is a Confirmation Dialog?
A confirmation dialog is an action sheet that slides up with a list of choices, perfect for offering several options at once. 🗂️
Dialog vs Alert
An alert centers on screen for one key decision. A dialog rises from the bottom and suits a menu of related actions instead.
Triggered by a Boolean
Like sheets and alerts, a dialog opens when a boolean state turns true. Store the flag and flip it from a button tap.
@State private var showDialog = falseThe confirmationDialog Modifier
Attach confirmationDialog to a view with a title and a boolean binding. SwiftUI presents the choices when the flag is true.
.confirmationDialog("Choose", isPresented: $showDialog) {
Button("Photo Library") { }
}Listing Choices as Buttons
Each option is a button inside the dialog. SwiftUI stacks them and runs the action of whichever one the user taps.
Button("Camera") { }
Button("Photo Library") { }A Destructive Option
Use the .destructive role for risky choices like delete. The button turns red so users notice before committing.
Button("Delete Account", role: .destructive) { }The Cancel Button
SwiftUI adds a Cancel button automatically. You can also supply your own with role .cancel to control its wording.
Button("Not now", role: .cancel) { }Adding a Title Message
Pass a message closure to explain the choice. It shows as a short caption above the buttons to guide the decision.
.confirmationDialog("Remove item?", isPresented: $show) {
Button("Remove", role: .destructive) { }
} message: {
Text("You can add it again later.")
}Reacting to a Choice
Each button's action runs on tap, then the dialog closes. Put the matching logic, like pick or delete, inside that closure.
Button("Save") { saveDocument() }Dialogs Adapt by Device
On iPhone a dialog rises as an action sheet. On iPad and Mac it appears as a popover near the control that opened it.
When to Use a Dialog
Reach for a dialog when a single tap could mean several things, like sharing or choosing an image source. It keeps options tidy.
Quick Check
When is a confirmation dialog the better choice over an alert?
Recap: Dialogs
You can now present a confirmation dialog from a boolean, list action buttons, and mark destructive choices in red. You finished the course! 🎉
よくある質問
「確認ダイアログ」レッスンは無料ですか?
はい。「確認ダイアログ」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、SwiftUI Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 SwiftUI Academyコースには全4レッスンが含まれています。
「確認ダイアログ」で何を学びますか?
confirmationDialogで破壊的な操作を選択できるようにします。 ブラウザで直接実行するハンズオンコードでSwiftUI Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
SwiftUI Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのSwiftUI Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「確認ダイアログ」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このSwiftUI Academyレッスンでコードを書いて実行できますか?
はい。すべてのSwiftUI Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。