LoginSignup
17
15

More than 5 years have passed since last update.

Xcodeのテンプレートを自分ごのみにアレンジする

Last updated at Posted at 2016-03-17

Xcodeのインデントはデフォルトで4ですが、これを2に変えたりしても新規に作成したUIViewControllerのファイルは4で生成されます。
他にも、UIViewControllerにprepareForSegueのコメントアウトやdidReceiveMemoryWarningが最初から直書きされていたりして毎回生成時に自分ごのみに整頓している人も多いのではないでしょうか。

Xcodeのソースコードテンプレートは

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/File Templates/

に配置してあります。

例えばUIViewControllerのSwiftのテンプレートは
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/File Templates/Source/Cocoa Touch Class.xctemplate/UIViewControllerSwift
にあります。

___FILEBASENAME___.swift

//
//  ___FILENAME___
//  ___PROJECTNAME___
//
//  Created by ___FULLUSERNAME___ on ___DATE___.
//___COPYRIGHT___
//

import UIKit

final class ___FILEBASENAMEASIDENTIFIER___: ___VARIABLE_cocoaTouchSubclass___ {

  override func viewDidLoad() {
    super.viewDidLoad()
  }

}

こんな感じに書き換えておけば次回から

ViewController.swift
//
//  ViewController.swift
//  NightFox
//
//  Created by noppefoxwolf on 2016/03/17.
//  Copyright © 2016年 noppelab.com All rights reserved.
//

import UIKit

final class ViewController: UIViewController {

  override func viewDidLoad() {
    super.viewDidLoad()
  }

}

こんな感じで生成されます。
場所的にXcodeを上書きすると消える感じがするのでエイリアス貼るなりgitで管理するなりすると良いと思います。

いじょ

17
15
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
17
15