LoginSignup
6
3

More than 3 years have passed since last update.

なるべくコンフリクトしないXcodeプロジェクトの作成手順

Last updated at Posted at 2019-06-10

はじめに

この記事は、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を作成します。今回使用する設定はmacOSXcodeSwiftの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.xcconfigRelease.xcconfigでPod用xccondigのincludeを行います。

Debug.xcconfig
// 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
.
.

Release.xcconfig
// 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

参考

6
3
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
6
3