0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

簡単にネイティブSwiftをバイブコーディングする

Last updated at Posted at 2025-09-03

概要

  • ネイティブ Swift(Flutterじゃない)
  • Cursor や Claude Code、Gemini CLI などを使ってバイブコーディングしたい
  • 実機にビルドして確認したい
  • Xcode 開かなくても進めることはできるが、結局併用は必須

1. 実機のUDID取得

実機に繋いで以下のコマンドを実行

xcrun xcdevice list | jq '.[] | select(.simulator == false) | .'

“identifier” の値をコピー

いい感じにスクリプトに動的に組み込んでも良い。

ビルド、インストール、起動のコマンドを用意

bin
└── build-and-launch.sh
#!/bin/zsh

# ビルドして実機で起動する。

set -eu

SCHEME="スキーム名"
PROJECT="プロジェクト名.xcodeproj"
CONFIG="Debug"
DERIVED="./build"
UDID="自分のUDID"
UNINSTALL_APP=${1:-false}
APP_PATH="$DERIVED/Build/Products/$CONFIG-iphoneos/$SCHEME.app"
BUNDLE_ID=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleIdentifier' "$APP_PATH/Info.plist")

# ビルド
xcodebuild \
  -project "$PROJECT" \
  -scheme "$SCHEME" \
  -configuration "$CONFIG" \
  -destination 'generic/platform=iOS' \
  -derivedDataPath "$DERIVED" \
  -allowProvisioningUpdates \
  build

# 既存のアプリを削除(引数のフラグで分岐)
if [ "$UNINSTALL_APP" = "--uninstall" ]; then
  xcrun devicectl device uninstall app --device "$UDID" "$BUNDLE_ID" || true
fi

# インストール
xcrun devicectl device install app --device "$UDID" "$APP_PATH"

# 起動
xcrun devicectl device process launch --device "$UDID" --terminate-existing "$BUNDLE_ID"

cursorrules に入れておく

.cursorrules
- コードを修正したら、ビルドが通るかどうか以下のコマンドで必ず確認する。
  `./bin/build-and-launch.sh`

ここは使ってるツールに合わせて。

Xcodeは併用必須

  • VSCode の Swift エクステンションはエコシステム的に充実しておらず、少なくとも自分がパッと試した限りではまともに動かなかった。
    ファイルが読み込めずカスタム定義が読み込めなかったり、コードジャンプが効かなかったりと VSCode 上でちゃんとコードを書くのは厳しい。
  • 画像やInfo.plistなどはXcodeを経由するべき。
  • 上記の方法だとログを見たりブレイクポイントを設定したりすることはできない。
    ログはもしかしたらコマンドをどうこうすれば見れるのかもしれない。
  • なんかたまにLLMからのビルドが失敗する。
    別のアプリとして起動されたり、コマンドの実行は完了してるのに立ち上がらなかったり。細かく見れば原因がわかるのかもしれない。

おしまい

これでいつも通り Cursor でバイブコーディングすれば自動で実機にインストールされて触れる。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?