MacなしでiOSアプリを作る。借りたMacでCodexを使う
Macを持っていなくても、本物のiPhoneアプリを作れます。Macを借りて、Macでの作業はCodexに任せます。 CodexはOpenAIのコーディングエージェントです。作業を始める前に、AGENTS.mdというファイルを読みます。 当社は、MacでiOSアプリをビルドする方法をCodexに正確に伝えるファイルを書きました。 2026年11月14日に、当社のMacの1台で最初の3つのステップを試しました。 このページでは各ステップを説明し、ファイルの全文を載せます。
それでもMacが必要な理由
CodexはどのパソコンでもSwiftを書けます。しかし、iOSアプリをビルドできるのはMacだけです。 Xcode、シミュレータ、Appleの署名ツールはmacOSでしか動きません。 これらがなければ、Codexは実行も確認もできないコードを書くだけです。 これらがあれば、アプリをビルドし、シミュレータで開き、スクリーンショットを撮って、自分の作業を確認できます。 詳しくは、iOSのコーディングエージェントにMacが必要な理由のページをご覧ください。
必要なもの
- 手元のパソコンから接続できるMac。MacRunのMacは、ニュージャージー州にある自社の専用施設に置いた、専用のM6 Mac miniです。 Xcode 27.1とHomebrewが入っています。エージェントプランでは、Codexもインストール済みです。
- ChatGPTアカウント。Codexはこれでサインインします。お使いのプランの利用上限が適用されます。
- Apple Developerアカウント(後で)。必要なのは、自分のiPhoneやApp Storeにアプリを入れるときだけです。 費用は年間99 USDです。シミュレータのステップにはアカウントは要りません。
- Xcodeの経験は不要。ファイルは、各ステップをやさしい言葉で説明し、スクリーンショットを見せるようCodexに指示します。
AGENTS.mdの役割
AGENTS.mdは、指示を書いたテキストファイルです。Codexはタスクのたびに、最初にこれを読みます。 ~/.codex/AGENTS.mdにあるファイルは、すべてのプロジェクトに適用されます。 プロジェクトフォルダ内のファイルは、そのプロジェクトに適用されます。
当社のファイルは、Codexに4つのことを伝えます。
- Macに何がインストールされているか、その確認方法。
- ルール。アプリごとに別のgitリポジトリにする。キーやパスワードをgitに入れない。 Apple IDのパスワードを絶対に聞かない。動くと言う前に、作業を確認する。
- アプリを作成、ビルド、実行、テストするための正確なコマンド。
- APIキーを使って、テストビルドをTestFlightにアップロードする方法。
ステップ0:ファイルを配置する
MacでTerminalを開くか、SSHで接続します。ファイルをCodexのフォルダにダウンロードし、Codexを起動します。 Codexが入っていなければ、先にHomebrewでインストールしてください。
mkdir -p ~/.codex curl -fsSL https://macrun.dev/blueprint/AGENTS.md -o ~/.codex/AGENTS.md brew install --cask codex # only if codex is missing codex
初回は「Sign in with ChatGPT」を選びます。サインインはMac上のブラウザで開きます。 ブラウザに表示したMacのデスクトップから、サインインを完了できます。
ステップ1:アプリを説明して、Codexに作らせる
Xcodeのプロジェクトファイルは、人にもエージェントにも手で書くのが難しいものです。 そこでファイルは、XcodeGenを使うようCodexに指示します。Codexが短いproject.ymlを書き、XcodeGenがそれを本物のXcodeプロジェクトに変えます。 XcodeGenが必要になると、CodexがHomebrewでインストールします。
あとは、作りたいものを自分の言葉でCodexに伝えます。たとえば次のようにします。
Make a new iPhone app called Tally. It has one big button that counts taps and remembers the count. Use SwiftUI. Follow AGENTS.md and show me a screenshot when it runs.
Codexは、com.yournameのような、あなた自身の逆ドメインを聞いてきます。 それがアプリのバンドルIDの先頭になります。
ステップ2:ビルドして、実行して、スクリーンショットを撮る
この繰り返しこそが、iOSでエージェントを役立つものにします。Codexはアプリをビルドし、シミュレータを起動し、アプリをインストールしてスクリーンショットを撮ります。 そして、その画像を見ます。レイアウトが崩れていれば、それに気づいて、あなたより先に直します。
SIM="iPhone 17" xcodebuild -scheme Tally -destination "platform=iOS Simulator,name=$SIM" \ -derivedDataPath build build xcrun simctl bootstatus "$SIM" -b xcrun simctl install "$SIM" build/Build/Products/Debug-iphonesimulator/Tally.app xcrun simctl launch "$SIM" com.yourname.tally sleep 3; xcrun simctl io "$SIM" screenshot /tmp/shot.png
これらを自分で入力する必要はありません。Codexが実行します。 何をしているかがわかるように、ここに載せています。
ステップ3:テストを実行する
プロジェクトには、最初からテストターゲットがあります。機能ごとにテストを追加するよう、Codexに頼んでください。 Codexは、1つのコマンドですべてのテストを実行します。
xcodebuild test -scheme Tally \ -destination "platform=iOS Simulator,name=iPhone 17" -derivedDataPath build
実際に試した結果
2026年11月14日に、当社のM6 Macの1台でステップ1から3を実行しました。 XcodeGen 2.46、Xcode 27.1、iPhone 17のシミュレータを使いました。 プロジェクトが生成され、アプリがビルドされて動き、スクリーンショットが返ってきて、テストも通りました。 その後、うまくいった手順をそのまま書き留めました。それがこのファイルです。
ステップ4:TestFlightでiPhoneに入れる
リモートのMacからは、あなたの近くにあるiPhoneは見えません。スマートフォンをMacにつなぐこともできません。 アプリをスマートフォンに入れるには、TestFlightを使います。このステップにはApple Developer Programが必要です。
- App Store Connectで、同じバンドルIDのアプリを作成します。
- App Managerの役割を持つApp Store Connect APIキーを作成します。 .p8ファイルは一度だけダウンロードできます。Macの~/.appstoreconnect/private_keys/に置いてください。
- キーID、発行者ID、Team IDをCodexに伝えます。
- テストビルドのアップロードをCodexに頼みます。Codexはアプリをアーカイブし、xcodebuildとあなたのキーでアップロードします。
- iPhoneのTestFlightアプリから、ビルドをインストールします。
CodexがApple IDのパスワードを必要とすることはありません。署名とアップロードはキーが行います。 はっきり言うと、このステップはまだ当社のフリートで最後まで実行していません。開発者アカウントが必要だからです。 APIキーでアップロードする、Appleが文書化したxcodebuildの手順に沿っています。 App Store Connectについては、当社の公開ガイドで詳しく説明しています。
ステップ5:必要なら自動化する
- プッシュのたびにアップロードする。同じMacでGitHub Actionsのrunnerを動かせます。当社のセルフホストrunnerのガイドをご覧ください。
- 決まった時間にタスクを実行する。LaunchAgentを使えば、決まった時刻にタスクを渡して
codex execを起動し、結果を記録できます。ファイルは、それを止める方法もあなたに見せるようCodexに指示します。
AGENTS.mdの全文
ここからコピーするか、AGENTS.mdをダウンロードしてください。MacRunのMac向けに書いています。別のMacで使う場合は、最初の数行をそのMacに入っているものに合わせて変えてください。
# This Mac: how to build iOS apps here
You are a coding agent on a dedicated MacRun Mac mini (M6, macOS 27). The person you work with
may be new to iOS. Explain what you do in plain words, one step at a time, and show them the
result (a simulator screenshot) after each change they can see.
## What is installed
- Xcode 27.1 with iOS 27.1, 27.0 and 26.5 simulators. Check with `xcrun simctl list devices available`.
- Homebrew (`/opt/homebrew/bin`), git, Node, Ruby, fastlane, Codex and Claude Code.
- Not installed until needed: XcodeGen. Install it with `brew install xcodegen`.
## Rules
- Keep projects in `~/Projects/<AppName>`. Make each one a git repo and commit after each working step.
- Never put secrets in git: no `.p8` keys, passwords or API tokens. Keep App Store Connect keys in
`~/.appstoreconnect/private_keys/` and add `*.p8` to `.gitignore`.
- Never ask the person for their Apple ID password. Signing and uploads use an App Store Connect API key.
- The Mac does not sleep. Do not change power, sharing or network settings.
- Check the work yourself: build, run tests, and look at a screenshot before you say it works.
## 1. Create a new app
Xcode projects are hard to write by hand, so describe the project in `project.yml` and let XcodeGen
make the `.xcodeproj`:
```yaml
name: Hello
options:
bundleIdPrefix: com.example # ask the person for their own reverse domain
deploymentTarget: { iOS: "26.0" }
targets:
Hello:
type: application
platform: iOS
sources: [Sources]
settings:
base:
PRODUCT_BUNDLE_IDENTIFIER: com.example.hello
MARKETING_VERSION: "1.0"
CURRENT_PROJECT_VERSION: "1"
GENERATE_INFOPLIST_FILE: YES
INFOPLIST_KEY_UILaunchScreen_Generation: YES
INFOPLIST_KEY_UISupportedInterfaceOrientations: UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight
TARGETED_DEVICE_FAMILY: "1" # iPhone only; use "1,2" for iPad too
HelloTests:
type: bundle.unit-test
platform: iOS
sources: [Tests]
dependencies: [{ target: Hello }]
settings:
base:
GENERATE_INFOPLIST_FILE: YES
schemes:
Hello:
build: { targets: { Hello: all } }
test: { targets: [HelloTests] }
```
Write SwiftUI code in `Sources/` (an `App` struct and a `ContentView`), tests in `Tests/`, then run
`xcodegen generate`. Run it again whenever you add or remove files.
## 2. Build and run in the simulator
```sh
SIM="iPhone 17"
xcodebuild -scheme Hello -destination "platform=iOS Simulator,name=$SIM" \
-derivedDataPath build build
xcrun simctl bootstatus "$SIM" -b # boots it and waits until ready
xcrun simctl install "$SIM" build/Build/Products/Debug-iphonesimulator/Hello.app
xcrun simctl launch "$SIM" com.example.hello
sleep 3; xcrun simctl io "$SIM" screenshot /tmp/shot.png
```
Open `/tmp/shot.png` to check the screen, and show it to the person. They can also open the
Mac's desktop in Screen Sharing or the browser to look for themselves.
## 3. Run the tests
```sh
xcodebuild test -scheme Hello -destination "platform=iOS Simulator,name=iPhone 17" -derivedDataPath build
```
## 4. Test builds and uploads to TestFlight
This needs the person's paid Apple Developer account. Do these steps with them:
1. They create the app in App Store Connect (Apps, +, New App) with the same bundle ID.
2. They create an API key in App Store Connect (Users and Access, Integrations, App Store Connect API,
role App Manager). They download the `.p8` file once and put it in `~/.appstoreconnect/private_keys/`.
You need three values: the key ID, the issuer ID, and their Team ID (Membership page).
3. Set the Team ID in `project.yml` (`DEVELOPMENT_TEAM`, with `CODE_SIGN_STYLE: Automatic`) and regenerate.
Then each upload is:
```sh
KEY_ID=...; ISSUER=...; KEY=~/.appstoreconnect/private_keys/AuthKey_$KEY_ID.p8
AUTH="-allowProvisioningUpdates -authenticationKeyPath $KEY -authenticationKeyID $KEY_ID -authenticationKeyIssuerID $ISSUER"
xcodebuild -scheme Hello -configuration Release -destination "generic/platform=iOS" \
-archivePath build/Hello.xcarchive archive $AUTH
xcodebuild -exportArchive -archivePath build/Hello.xcarchive \
-exportOptionsPlist ExportOptions.plist -exportPath build/export $AUTH
```
`ExportOptions.plist`:
```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"><dict>
<key>method</key><string>app-store-connect</string>
<key>destination</key><string>upload</string>
<key>teamID</key><string>TEAM_ID_HERE</string>
</dict></plist>
```
Raise `CURRENT_PROJECT_VERSION` before every upload; App Store Connect rejects a repeated build number.
The build shows in TestFlight after Apple processes it, which can take a while. If the person
prefers fastlane, `fastlane pilot` does the same with the same API key.
## 5. Automate it
- To upload on every push, a GitHub Actions self-hosted runner can run on this Mac. Ask first.
- To run a task on a schedule, use a LaunchAgent in `~/Library/LaunchAgents` that calls
`codex exec "<task>"`, and log to a file. Show the person how to turn it off.
## Limits
- No physical iPhone can be plugged in. Use the simulator here and TestFlight on their own phone.
- Apple's review is done by Apple. You can prepare the build, but the person submits for review.
Codexとアプリを作るときのコツ
- 一度に頼む変更は1つだけ、小さくします。変更のたびにスクリーンショットを見ます。
- うまくいったステップごとに、Codexにコミットさせます。そうすれば、悪い変更も簡単に元に戻せます。
- リポジトリをGitHubにプッシュします。そうすれば、コードはMacの外にも残ります。
- キーやパスワードをチャットに貼らないでください。.p8ファイルは自分でMacに置きます。
- 何かおかしいと思ったら、見えたものをそのまま伝えます。Codexはもう一度スクリーンショットを撮れます。
できないこと
- Macにつないだスマートフォンでのテストはできません。シミュレータとTestFlightを使ってください。
- App Storeのアプリは、すべてAppleが審査します。審査への提出はご自身で行います。
- Codexは間違えることがあります。何を出すかはあなたが決めます。
- 当社が提供するのはMacとファイルです。アプリの開発は行いません。
費用
MacRunのエージェント用Macは月額$169で、Xcode 27.1とCodexがインストール済みです。 スリープしないので、あなたのパソコンの電源が切れていても、Codexは作業を続けられます。 Codexの費用はChatGPTのプランに含まれます。Apple Developer Programは年間99 USDで、必要なのはTestFlightとApp Storeのときだけです。
このためにMacを借りなくてよい人
すでにMacを持っているなら、それを使ってください。同じファイルがそこでも使えます。 コードを一切書かずにアプリを作りたいなら、ノーコードのツールのほうが合うかもしれません。 ほかの方法については、MacなしでiOSアプリを開発する方法をお読みください。
よくある質問
AIエージェントを使えば、MacなしでiOSアプリを作れますか?
+
エージェントはどこでもコードを書けます。しかし、iOSアプリのビルドと実行にはXcodeが必要で、XcodeはmacOSでしか動きません。Macを借りてCodexを動かせば、エージェントがビルドし、シミュレータで実行し、自分の作業を確認できます。
AGENTS.mdとは何ですか?
+
Codexがタスクのたびに最初に読む、指示を書いたテキストファイルです。~/.codex/AGENTS.mdにあるファイルは、すべてのプロジェクトに適用されます。プロジェクトフォルダ内のファイルは、そのプロジェクトに適用されます。当社のファイルは、MacでiOSアプリを作成、ビルド、テスト、アップロードする方法をCodexに伝えます。
このAGENTS.mdは試しましたか?
+
2026年11月14日に、当社のM6 Macの1台でステップ1から3を試しました。XcodeGen 2.46、Xcode 27.1、iPhone 17のシミュレータを使いました。TestFlightのステップは、まだ最後まで実行していません。App Store Connect APIキーでアップロードする、Appleが文書化したxcodebuildの手順に沿っています。
Apple Developerアカウントは必要ですか?
+
シミュレータでアプリをビルドして動かすだけなら不要です。iPhoneでTestFlightを使うには、年間99 USDのApple Developer Programが必要です。App Storeで公開するときも必要です。
自分のiPhoneでアプリを試せますか?
+
はい、TestFlightで試せます。Codexがテストビルドをアーカイブしてアップロードし、あなたがTestFlightアプリからインストールします。リモートのMacにiPhoneをつなぐことはできません。
CodexはApple IDのパスワードを必要としますか?
+
いいえ。ファイルは、パスワードを絶対に聞かないようCodexに指示しています。署名とアップロードには、App Store Connect APIキーを使います。キーはご自身で作成し、Macに置きます。