0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[Xcode]変数名や関数名の変更が楽になるRename機能の使い方

Last updated at Posted at 2025-05-14

Renameについて

Xcodeでよく利用する便利機能を紹介します。
Rename機能は変数名や関数名を変更したいときに、全ての使用箇所を自動で一括変更してくれる機能です。
レビューで命名の修正指摘を受けたときにも便利ですし、タイポしたときにも重宝します。
今回は、Xcodeで変数名を一括で変更できる「Rename」機能についてご紹介します。

Rename手順

下記のようにButtonBottonとタイポしたプロパティを用意します。

import UIKit

class ViewController: UIViewController {
    
    @IBOutlet weak var renameBotton: UIButton!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        bind()
    }
    
}

extension ViewController {
    func bind () {
        renameBotton.isHidden = false
        renameBotton.tintColor = .red
        renameBotton.layer.cornerRadius = 10
    }
}

1️⃣対象プロパティを右クリック → Refactor → Rename を選択

image.png

2️⃣新しい名前を入力し、Renameボタンを押す

今回は renameBotton → renameButton に修正します。
image (1).png

✅一括変更が完了!

全ての使用箇所が自動で変更されました!
image.png

まとめ

Rename機能を使えば、変数名・関数名を安全に一括で変更できます。
タイポやレビューでの命名修正など、使用頻度の高い機能なので覚えておくと便利です。
特にStoryboardと接続しているIBOutletの修正は手動で直すとミスも起きやすいので、この機能を使ってミスを防ぐこともできます。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?