Xcodeで新規プロジェクトを作るときに設定したプロダクト名を後から変更しようとした際の手順を備忘録としてまとめておきます。
Xcodeのバージョンは8.2です。
準備
- Xcodeで新規プロジェクトを作成します。テンプレートは
Single View Applicationを使用し、
Product NameはSampleとします。
変更
-
PROJECTのSampleを選択する。
-
Identity and TypeのNameを変更します。今回はNewSampleとします。
- プロンプトが立ち上がるので
Renameを選択します。
- ナビゲーションバーから
Product->Scheme->Edit Scheme...を選択するとプロンプトが立ち上がるのでManage Schemes...を選択します。
-
+ボタンを選択するともう一つプロンプトが立ち上がるのでNameの欄がNewSampleとなっていることを確認してOKを選択します。
- Sampleをチェックし、
-ボタンを選択するとプロンプトが立ち上がるのでDeleteを選択します。
- NewSampleをチェックし、
Closeボタンを選択してプロンプトを閉じます。
- ナビゲーターエリアのディレクトリ名も変更します。Sampleを選択し、
Identity and TypeのNameをNewSampleに変更します。同様にSampleTestsを選択し、Identity and TypeのNameをNewSampleTestsに変更します。
- SampleTests.swiftをNewSampleTests.swiftにリネームして以下のように書き換えます。
import XCTest
@testable import NewSample
class NewSampleTests: XCTestCase {
override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}
func testExample() {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
func testPerformanceExample() {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
}
}
- これでXcodeでのディレクトリ構成は変更されたのですが、treeで見ると実際のディレクトリ構成とは異なっています。
これを合わせるためにSynxを使用します。
- Synxについては「Xcodeのファイルを整理する Synx」を参考にさせていただきました。
次のコマンドを実行します。
$ synx NewSample.xcodeproj/
- この段階でtreeで見たときのディレクトリ構成です。
プロジェクトトップの名前をNewSampleに変更して、空のディレクトリSampleとSampleTestsを削除すると新規作成でProduct NameをNewSampleで設定したものと同じ構成のものができます。