https://youtu.be/ntAKQXss4Yg?si=cRbSUlyI4ZRThh43
Xcode で 最短時間 でアプリを作るなら、以下の流れで進めるのがベスト!

1️⃣ Xcode で新規プロジェクトを作成
- Xcode を開く →
Create a new Xcode projectを選択 iOS→Appを選択SwiftUIを選択(UIKit より速い)- プロジェクト名を入力(例:
FastApp) Use Core Dataのチェックを外す(使わないので時間短縮)Next→保存先を選択→Create
2️⃣ Xcode にコードをコピペ(1分)
ContentView.swift に以下をコピペするだけで、シンプルなボタンアプリが動く。
swiftコードをコピーする
import SwiftUI
struct ContentView: View {
@State private var count = 0
var body: some View {
VStack {
Text("カウント: \(count)")
.font(.largeTitle)
.padding()
Button("タップして増やす") {
count += 1
}
.font(.title2)
.padding()
.background(Color.blue)
.foregroundColor(.white)
.cornerRadius(10)
}
}
}
#Preview {
ContentView()
}
✅ Xcode 14.2 で正しいプレビュー記法
あなたの環境では、以下のように書く必要があります。
swiftコードをコピーする
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
📌 SceneDelegate.swift を修正
UIKit の SceneDelegate.swift を SwiftUI 互換にする。
- SceneDelegate.swift を開く
window.rootViewControllerの代わりに以下のコードを書く:
swiftコードをコピーする
import SwiftUI
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
let contentView = ContentView()
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
window.rootViewController = UIHostingController(rootView: contentView)
self.window = window
window.makeKeyAndVisible()
}
}
}
3️⃣ シミュレーターで即実行(10秒)
- 画面上部の「▶(Run)」ボタンをクリック
- シミュレーターが起動し、アプリが動く! 🎉
コメントを残す