4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Xcodeでプロジェクト内の全ての文字列を置換したい時の方法

Last updated at Posted at 2023-12-11

概要

プロジェクト内のクラス名などを一斉に変更する際、今まではRefactor>Renameを使っていたのですが、偶にエラーが出て置換できない例が出てきたり、何故か置換対象として表示されないことがあります。

一般的な対処法であるDerived Dataの削除などをしても上手くいかず、違う方法を調べたらXcodeの機能で入力したキーワードでプロジェクト内を検索し、一斉置換する方法があったので方法を残しておきます。


詳細

以下の画像のように左上のナビゲータバーの虫眼鏡アイコンを選択し、検索機能に遷移します。

スクリーンショット 2023-12-08 18.52.52.png

Find>Text>Containingの内、Findをクリックすると、選択肢が表示されるため、Replaceを選択します。

スクリーンショット 2023-12-08 18.53.13.png

上の入力フィールドに検索したい値を、下の入力フィールドに置換したい値を入れ、上から順に置換したい場合はReplaceを、一斉置換したい場合にはReplace Allをクリックします。

(Replace All実行前)
スクリーンショット 2023-12-08 18.54.13.png

実行時にどの要素の置換に成功したかが表示されます。
下記の画像のように、置換に成功した場合には緑色のアイコンで表示され、失敗した場合には赤色のアイコンで表示されます。

(Replace All実行時)
スクリーンショット 2023-12-08 18.53.40.png

再度同じ検索条件で検索してみると、確かに置換に失敗した箇所のみが表示されています。
また、プロジェクト情報に関しては変更されると支障が出やすい情報であるためか、一斉置換はできないようです。

(Replace All実行後)
スクリーンショット 2023-12-08 18.54.02.png

Refactor>Renameが上手く動作しない時にはこちらの方法を試してみるのもありかもしれません。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?