LoginSignup
173
152

More than 5 years have passed since last update.

Xcodeのファイルを整理する Synx

Last updated at Posted at 2015-01-06

Xcodeのグループに合わせて、
ファイルを整理してくれる便利ツールを紹介します。

リンク

インストール

$ gem install synx

使い方

$ synx path/to/my/project.codeproj

CocoaPods を利用する場合は
先に Synx で整理してから
$ pod install
を行ったほうがいいみたいです。

Advanced

-e 指定したグループの整理はしない
-p Xcodeで管理されていないファイルを削除

sh
$ synx -p -e "/MyProject/My Group" -e /MyProject/MyGroup ./MyProject.xcodeproj/

使用例

新規プロジェクトを作成しました。
初期のグループはこんな感じですよね。
ss_1.png

ディレクトリ構成をtreeコマンドで確認してみましょう。

sh
$ tree
.
├── MyProject
│   ├── AppDelegate.h
│   ├── AppDelegate.m
│   ├── Base.lproj
│   │   ├── LaunchScreen.xib
│   │   └── Main.storyboard
│   ├── DetailViewController.h
│   ├── DetailViewController.m
│   ├── Images.xcassets
│   │   └── AppIcon.appiconset
│   │       └── Contents.json
│   ├── Info.plist
│   ├── MasterViewController.h
│   ├── MasterViewController.m
│   └── main.m
├── MyProject.xcodeproj
│   ├── project.pbxproj
│   ├── project.xcworkspace
│   │   ├── contents.xcworkspacedata
│   │   └── xcuserdata
│   │       └── Nomura.xcuserdatad
│   │           └── UserInterfaceState.xcuserstate
│   └── xcuserdata
│       └── Nomura.xcuserdatad
│           └── xcschemes
│               ├── MyProject.xcscheme
│               └── xcschememanagement.plist
└── MyProjectTests
    ├── Info.plist
    └── MyProjectTests.m

12 directories, 18 files

このようにMyProjectフォルダに全てのファイルがある状態です。
ごちゃごちゃしててわかりにくい。。。

ではまずXcode上でグループ分けをします。
簡単にこんな感じにしてみました。

ss_2.png

synxコマンドで整理してみましょう

sh
$ synx ./MyProject.xcodeproj/

  Syncing files that are included in Xcode project...
  MyProject/
    Sources/
      Defaults/
        AppDelegate.h
        AppDelegate.m
      Views/
        Master/
          MasterViewController.h
          MasterViewController.m
        Detail/
          DetailViewController.h
          DetailViewController.m
        Base.lproj/
          Main.storyboard
    Resources/
      Images/
        Images.xcassets
        Base.lproj/
          LaunchScreen.xib
    Supporting Files/
      Info.plist (build settings amended: INFOPLIST_FILE)
      main.m
  MyProjectTests/
    MyProjectTests.m
    Supporting Files/
      Info.plist (build settings amended: INFOPLIST_FILE)
  Products/ (excluded)


  Syncing files that are not included in Xcode project..
  MyProject/
    Sources/
      Defaults/
      Views/
        Master/
        Detail/
        Main.storyboard/
    Resources/
      Images/
        LaunchScreen.xib/
    Supporting Files/
  MyProjectTests/
    Supporting Files/
  Products/ (excluded)

なにやらカラフルなものがでて、一瞬で整理されました。
treeコマンドで確認してみましょう。

sh
$ tree
.
├── MyProject
│   ├── Resources
│   │   └── Images
│   │       └── Images.xcassets
│   │           └── AppIcon.appiconset
│   │               └── Contents.json
│   ├── Sources
│   │   ├── Defaults
│   │   │   ├── AppDelegate.h
│   │   │   └── AppDelegate.m
│   │   └── Views
│   │       ├── Base.lproj
│   │       │   ├── LaunchScreen.xib
│   │       │   └── Main.storyboard
│   │       ├── Detail
│   │       │   ├── DetailViewController.h
│   │       │   └── DetailViewController.m
│   │       └── Master
│   │           ├── MasterViewController.h
│   │           └── MasterViewController.m
│   └── Supporting\ Files
│       ├── Info.plist
│       └── main.m
├── MyProject.xcodeproj
│   ├── project.pbxproj
│   ├── project.xcworkspace
│   │   ├── contents.xcworkspacedata
│   │   └── xcuserdata
│   │       └── Nomura.xcuserdatad
│   │           └── UserInterfaceState.xcuserstate
│   └── xcuserdata
│       └── Nomura.xcuserdatad
│           └── xcschemes
│               ├── MyProject.xcscheme
│               └── xcschememanagement.plist
└── MyProjectTests
    ├── MyProjectTests.m
    └── Supporting\ Files
        └── Info.plist

21 directories, 18 files

[Sources]、[Resources]、[Views]、各グループ名のディレクトリが作成され、
その中にファイルがはいりました。

最初のディレクトリ整理で時間を取られていた時代はなんだったんだろう。。。

173
152
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
173
152