swift-development について
Swift開発者向けの開発スキルです。パッケージやアプリのビルド、テスト、フォーマット、シミュレーター管理を扱い、スクリプト、テンプレート、分野別の参考資料を含みます。
主な機能
- 01Swift Package作成用スクリプトとテンプレート
- 02SwiftPMとxcodebuildによるビルドとテスト
- 03SwiftコードのフォーマットとLint
- 04iOSシミュレーター管理スクリプト
- 05SwiftUI、並行処理、アーキテクチャの参考資料
活用シーン
- 01新しいSwiftライブラリパッケージの作成
- 02iOSアプリのビルドとテスト
- 03SwiftソースのフォーマットとLint
- 04シミュレーターの起動とアプリのインストール
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ hmohamed01/ swift-development --skill swift-developmentインストール後、Claude Code で/swift-developmentを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
assets/.swiftformat.swiftlint.ymlPackage.swift.templateassets/ExportOptions/ad-hoc.plistapp-store.plistdevelopment.plistreferences/architecture.mdbest-practices.mdcicd.mdcode-signing.mdconcurrency.mdsimctl.mdspm.mdswiftui-patterns.mdtesting-patterns.mdtroubleshooting.mdxcodebuild.mdscripts/format_and_lint.shnew_package.shrun_tests.shsimulator.sh詳細
Swift 開発
前提条件
- Xcode 15 以降がインストールされた macOS(Swift 6 の場合は Xcode 16 以降)
- Xcode Command Line Tools:
xcode-select --install - 確認:
xcodebuild -versionとswift --version
クイックスタート
新しい Swift パッケージ
# Use the included script for full setup
./scripts/new_package.sh MyLibrary --type library --ios --macos
# Or manually
swift package init --type library --name MyLibrary
ビルドとテスト
# SPM packages
swift build
swift test
# Xcode projects
xcodebuild -workspace App.xcworkspace -scheme App \
-destination 'platform=iOS Simulator,name=iPhone 15' build
# Use included script for common options
./scripts/run_tests.sh --parallel --coverage
フォーマットとリンティング
# Use included script
./scripts/format_and_lint.sh Sources/
# Check mode (CI)
./scripts/format_and_lint.sh --check
シミュレーターの管理
# Use included script
./scripts/simulator.sh list
./scripts/simulator.sh boot "iPhone 15"
./scripts/simulator.sh screenshot
./scripts/simulator.sh dark
主要なワークフロー
iOS アプリのビルド
# Debug build for simulator
xcodebuild -workspace App.xcworkspace -scheme App \
-destination 'platform=iOS Simulator,name=iPhone 15' \
build
# Release archive
xcodebuild archive \
-workspace App.xcworkspace -scheme App \
-archivePath ./build/App.xcarchive \
-configuration Release
# Export IPA (use templates from assets/ExportOptions/)
xcodebuild -exportArchive \
-archivePath ./build/App.xcarchive \
-exportPath ./build/export \
-exportOptionsPlist assets/ExportOptions/app-store.plist
テスト
# All tests
xcodebuild test -workspace App.xcworkspace -scheme App \
-destination 'platform=iOS Simulator,name=iPhone 15'
# Specific test
xcodebuild test -only-testing:AppTests/MyTestClass/testMethod
# With coverage
xcodebuild test -enableCodeCoverage YES \
-resultBundlePath ./TestResults.xcresult
アプリのインストール
# Install on booted simulator
xcrun simctl install booted ./Build/Products/Debug-iphonesimulator/App.app
# Launch
xcrun simctl launch booted com.company.app
公式ドキュメント
参考リンク(人間向け)
以下は、手動で閲覧するための Apple 公式ドキュメントへのリンクです。
| リソース | URL |
|---|---|
| Swift ドキュメント | https://developer.apple.com/documentation/swift |
| SwiftUI | https://developer.apple.com/documentation/swiftui |
| Swift Concurrency | https://developer.apple.com/documentation/swift/concurrency |
| Swift Testing | https://developer.apple.com/documentation/testing |
注:Apple のドキュメントサイトは JavaScript の SPA であり、WebFetch ではプログラムから取得できません。代わりに、以下の GitHub ベースのソースを使用してください。
WebFetch 対応ソース(GitHub の raw URL)
必ず raw.githubusercontent.com の URL を使用してください。通常の github.com の URL は文字化けした HTML/JSON を返します。
ベース URL のプレフィックス:https://raw.githubusercontent.com/apple
Swift Testing(/swift-testing/main/):
| リソース | パス |
|---|---|
| README | README.md |
| テストの定義 | Sources/Testing/Testing.docc/DefiningTests.md |
| テストの整理 | Sources/Testing/Testing.docc/OrganizingTests.md |
| 期待値 | Sources/Testing/Testing.docc/Expectations.md |
| パラメーター化テスト | Sources/Testing/Testing.docc/ParameterizedTesting.md |
| Trait の概要 | Sources/Testing/Testing.docc/Traits.md |
| Trait のリファレンス | Sources/Testing/Testing.docc/Traits/Trait.md |
| タグの追加 | Sources/Testing/Testing.docc/AddingTags.md |
| コメントの追加 | Sources/Testing/Testing.docc/AddingComments.md |
| バグの関連付け | Sources/Testing/Testing.docc/AssociatingBugs.md |
| バグ識別子 | Sources/Testing/Testing.docc/BugIdentifiers.md |
| 添付ファイル | Sources/Testing/Testing.docc/Attachments.md |
| テストの有効化/無効化 | Sources/Testing/Testing.docc/EnablingAndDisabling.md |
| 実行時間の制限 | Sources/Testing/Testing.docc/LimitingExecutionTime.md |
| 並列化 | Sources/Testing/Testing.docc/Parallelization.md |
| 終了テスト | Sources/Testing/Testing.docc/exit-testing.md |
| 既知の問題 | Sources/Testing/Testing.docc/known-issues.md |
| 非同期コードのテスト | Sources/Testing/Testing.docc/testing-asynchronous-code.md |
| エラーのテスト | Sources/Testing/Testing.docc/testing-for-errors-in-swift-code.md |
| XCTest からの移行 | Sources/Testing/Testing.docc/MigratingFromXCTest.md |
| ビジョンと設計 | Documentation/Vision.md |
| CLI のデバッグ | Documentation/CommandlineDebugging.md |
| 環境変数 | Documentation/EnvironmentVariables.md |
その他の Swift パッケージ:
| リソース | Raw URL 全体 |
|---|---|
| Swift Async Algorithms | https://raw.githubusercontent.com/apple/swift-async-algorithms/main/README.md |
| Swift Collections | https://raw.githubusercontent.com/apple/swift-collections/main/README.md |
Swift Evolution の提案については、提案番号から raw URL を組み立ててください。
https://raw.githubusercontent.com/apple/swift-evolution/main/proposals/NNNN-proposal-name.md
例:https://raw.githubusercontent.com/apple/swift-evolution/main/proposals/0409-access-level-on-imports.md
ディレクトリの検索(提案番号やドキュメントのファイル名の検索)には、WebFetch ではなく WebSearch を使用してください。GitHub のディレクトリ一覧は解析できません。
ドキュメントを取得するタイミング
次のような場合は、WebFetch と GitHub の raw URL を使用します。
- Swift Testing:
@Test、#expect、#require、トレイト、またはパラメーター化テストの詳細が必要な場合 - Swift Evolution:新しい言語機能に関する採択済みの提案を確認する場合
- フレームワークの詳細:Apple のオープンソース Swift パッケージの機能を実装する場合
- 不明点がある場合:現在の API のパターンやベストプラクティスがわからない場合
URL の変換ルール:github.com/{owner}/{repo}/blob/{branch}/ を raw.githubusercontent.com/{owner}/{repo}/{branch}/ に置き換えます。
フォールバック:raw URL に対する WebFetch が失敗した場合は、site:github.com/apple {topic} というクエリで WebSearch を使用して正しいファイルパスを確認し、raw URL を組み立てます。
WebFetch 用のプロンプト例:「このドキュメントから主な機能、マクロ、使用例を抽出してください」
参照ファイル
特定のトピックに関する詳細なドキュメントです。
| トピック | ファイル |
|---|---|
| SwiftUI のパターン | references/swiftui-patterns.md |
| テストのパターン | references/testing-patterns.md |
| Swift 6 の並行処理 | references/concurrency.md |
| アーキテクチャのパターン | references/architecture.md |
| ベストプラクティス | references/best-practices.md |
| Swift Package Manager | references/spm.md |
| xcodebuild コマンド | references/xcodebuild.md |
| シミュレーターの操作 | references/simctl.md |
| コード署名 | references/code-signing.md |
| CI/CD のセットアップ | references/cicd.md |
| トラブルシューティング | references/troubleshooting.md |
同梱スクリプト
| スクリプト | 用途 |
|---|---|
scripts/new_package.sh | 設定ファイルを含む新しい Swift パッケージを作成します |
scripts/run_tests.sh | 一般的なオプションを指定してテストを実行します |
scripts/format_and_lint.sh | Swift コードをフォーマットし、リンティングします |
scripts/simulator.sh | シミュレーターをすばやく管理します |
アセットテンプレート
| アセット | 用途 |
|---|---|
assets/Package.swift.template | Swift パッケージのテンプレート |
assets/.swiftformat | SwiftFormat の設定 |
assets/.swiftlint.yml | SwiftLint の設定 |
assets/ExportOptions/ | アーカイブ書き出し用 plist テンプレート |
クイックリファレンス
基本コマンド
| タスク | コマンド |
|---|---|
| パッケージをビルド | swift build |
| リリース版をビルド | swift build -c release |
| テストを実行 | swift test |
| 依存関係を更新 | swift package update |
| シミュレーターを一覧表示 | xcrun simctl list devices |
| シミュレーターを起動 | xcrun simctl boot "iPhone 15" |
| アプリをインストール | xcrun simctl install booted ./App.app |
| コードをフォーマット | swiftformat . |
| コードをリンティング | swiftlint |
よく使う実行先
# iOS Simulator
-destination 'platform=iOS Simulator,name=iPhone 15'
# macOS
-destination 'platform=macOS'
# Generic iOS (for archives)
-destination 'generic/platform=iOS'