はじめに
この記事は、Swift歴1週間の素人が、チーム開発の時のコンフリクトを起こさないようなプロジェクトを作ったときの手順のまとめです。ご指摘などあれば、是非コメントまでお願い致します。
環境
- macOS 10.14.5
- Xcode 10.2.1
使用ツール
- XcodeGen
- CocoaPods
- xcconfig-extractor
- gibo
ツールのインストール
XcodeGen
brew install xcodegen
# 動作確認
xcodegen -h
Usage: xcodegen generate [options]
.
.
CocoaPods
brew install cocoapods
# 動作確認
pod --version
1.7.1
xcconfig-extractor
bash <(curl -sL https://raw.githubusercontent.com/toshi0383/scripts/master/swiftpm/install.sh) toshi0383/xcconfig-extractor
# 動作確認
xcconfig-extractor --version
0.5.0
gibo
brew install gibo
# 動作確認
gibo version
gibo 2.2.1 by Simon Whitaker <sw@netcetera.org>
https://github.com/simonwhitaker/gibo
プロジェクト作成
Xcodeでプロジェクトを作成
とりあえず作ります。
xcconfigの作成
Xcodeを一旦終了し、Termialで先程作ったプロジェクトに移動して、以下のコマンドを実行します。
プロジェクト直下のconfigs
ディレクトリ以下に、各ビルド用のxcconfig
が生成されたらOKです。
xcconfig-extractor <project_name>.xcodeproj configs
project.yml作成
下記のコードをコピーして、project.yml
をプロジェクト直下に作成します。
<project name>
の部分を使用しているプロジェクト名に置換すればOKです。
name: <project name>
fileGroups:
- configs
configFiles:
Debug: configs/Debug.xcconfig
Release: configs/Release.xcconfig
targets:
<project name>:
type: application
platform: iOS
sources: <project name>
configFiles:
Debug: configs/<project name>-Debug.xcconfig
Release: configs/<project name>-Release.xcconfig
settings:
CURRENT_PROJECT_VERSION: 1
scheme:
testTargets:
- <project name>Tests
- <project name>UITests
<project name>Tests:
type: bundle.unit-test
platform: iOS
sources: <project name>Tests
configFiles:
Debug: configs/<project name>Tests-Debug.xcconfig
Release: configs/<project name>Tests-Release.xcconfig
dependencies:
- target: <project name>
<project name>UITests:
type: bundle.ui-testing
platform: iOS
sources: <project name>UITests
configFiles:
Debug: configs/<project name>UITests-Debug.xcconfig
Release: configs/<project name>UITests-Release.xcconfig
dependencies:
- target: <project name>
xcodeprojファイルの作成
プロジェクト直下で以下のコマンドを実行します。新しくxcodeprojファイルが作成されればOKです。
xcodegen
.gitignore作成
giboを使って、.gitignore
を作成します。今回使用する設定はmacOS
とXcode
とSwift
の3つです。
gibo dump macOS Xcode Swift > .gitignore
.gitignore
を生成したら、Pods/
と*.xcworkspace
と*.xcodeproj/project.pbxproj
をgitの監視から外します。
CocoaPodsをセットアップ
以下のコマンドを実行。そこそこ時間かかります。
pod setup
Podfileを作成
pod init
Podfileを編集
platform :ios
の部分のコメントアウトされているので外します。
ビルドターゲットの設定をいれないとxcodegen + pod install
でエラーが発生します。
# Uncomment the next line to define a global platform for your project
platform :ios, '12.0'
target '<project name>' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for <project name>
target '<project name>Tests' do
inherit! :search_paths
# Pods for testing
end
target '<project name>UITests' do
inherit! :search_paths
# Pods for testing
end
end
Podのインストールを実行
以下のコマンドを実行します。Warningが結構出ますが、今回は無視で問題ないです(たぶん)。
pod install
xcconfigの編集
configs
以下のDebug.xcconfig
とRelease.xcconfig
でPod用xccondigのincludeを行います。
// Generated using xcconfig-extractor 0.5.0 by Toshihiro Suzuki - https://github.com/toshi0383/xcconfig-extractor
#include "Base.xcconfig"
+#include "../Pods/Target Support Files/Pods-<project name>/Pods-<project name>.debug.xcconfig"
ENABLE_TESTABILITY = YES
GCC_DYNAMIC_NO_PIC = NO
.
.
// Generated using xcconfig-extractor 0.5.0 by Toshihiro Suzuki - https://github.com/toshi0383/xcconfig-extractor
#include "Base.xcconfig"
+#include "../Pods/Target Support Files/Pods-<project name>/Pods-<project name>.release.xcconfig"
SWIFT_COMPILATION_MODE = wholemodule
VALIDATE_PRODUCT = YES
.
.
ビルド実行
Xcodeで再度プロジェクトを開き、ビルドを実行します。ビルドが通れば完了です。満を持してgit push
しましょう。
運用手順
プロジェクトをcloneしたときや、ライブラリを追加する時は、以下のコマンドを順番に実行すればOKです。
xcodegen
pod install
参考
- 【2019年版】チームが幸せなiOSプロジェクトの作り方 - Qiita
- GitHub - simonwhitaker/gibo: Easy access to gitignore boilerplates
- GitHub - toshi0383/xcconfig-extractor: Refactor BuildSettings into xcconfigs
- GitHub - yonaskolb/XcodeGen: A Swift command line tool for generating your Xcode project
- CocoaPods.org
- https://qiita.com/hirothings/items/7f6943db609ff88c10be