7
7

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 3 years have passed since last update.

SwiftUIのプレビューが動かなくなった時の対処方法

Last updated at Posted at 2021-09-24

本記事について

Xcode Previewsで起きたエラーの対処をメモする。

起きたこと

プレビューを実行すると途中でクラッシュしてしまい、以下のエラーメッセージが表示される。

CrashOnLaunchError: [あなたのプロジェクト名] app crashed on launch

The app [あなたのプロジェクト名] crashed while updating the preview. Look for crash logs in ~/Library/Logs/DiagnosticReports for more details.

結論

以下の記事に記載されているxcrun simctl --set previews delete allで対処できた。

Swift UI Preview Crash - https://developer.apple.com/forums/thread/661669?answerId=635975022#635975022

やったこと(ログ的な)

そこでDiagnosticReportsを見てみる。

$ cd ~/Library/Logs/DiagnosticReports

以下のようなファイルがあるので、このログを見てみる

$ cat postgres_2021-09-24-114053_⚪︎⚪︎⚪︎⚪︎MacBook-Pro.crash
Dyld Error Message:
  dyld: Using shared cache: 4A889CE9-8D7E-304E-A5F7-84D819B0BF9C
Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.67.dylib
  Referenced from: /usr/local/opt/postgresql/bin/postgres
  Reason: image not found

既視感のあるエラーだが、いまいち対処法が見つからないので、ネットで検索する。

そうすると、以下の記事を見つける。

Swift UI Preview Crash - https://developer.apple.com/forums/thread/661669?answerId=635975022#635975022

記事に記載されている、以下のコマンドを打つと、解消できた。

$ xcrun simctl --set previews delete all

xcrun simctl --set previews delete all って何??

理解が浅いので、なるべく一つ一つ調べて理解してみた。

xcrun

XcodeのCLIツール
指定されたコマンドラインツールを探して実行してくれる。

simctl

主にシミュレータの管理を行うための機能を持っている。

サブコマンドは以下の通り。

usage: simctl [--set <path>] [--profiles <path>] <subcommand> ...
       simctl help [subcommand]
Command line utility to control the Simulator

For subcommands that require a <device> argument, you may specify a device UDID
or the special "booted" string which will cause simctl to pick a booted device.
If multiple devices are booted when the "booted" device is selected, simctl
will choose one of them.

Subcommands:
	create              Create a new device.
	clone               Clone an existing device.
	upgrade             Upgrade a device to a newer runtime.
	delete              Delete specified devices, unavailable devices, or all devices.
	pair                Create a new watch and phone pair.
	unpair              Unpair a watch and phone pair.
	pair_activate       Set a given pair as active.
	erase               Erase a device's contents and settings.
	boot                Boot a device or device pair.
	shutdown            Shutdown a device.
	rename              Rename a device.
	getenv              Print an environment variable from a running device.
	openurl             Open a URL in a device.
	addmedia            Add photos, live photos, videos, or contacts to the library of a device.
	install             Install an app on a device.
	uninstall           Uninstall an app from a device.
	get_app_container   Print the path of the installed app's container
	install_app_data    Install an xcappdata package to a device, replacing the current contents of the container.
	launch              Launch an application by identifier on a device.
	terminate           Terminate an application by identifier on a device.
	spawn               Spawn a process by executing a given executable on a device.
	list                List available devices, device types, runtimes, or device pairs.
	icloud_sync         Trigger iCloud sync on a device.
	pbsync              Sync the pasteboard content from one pasteboard to another.
	pbcopy              Copy standard input onto the device pasteboard.
	pbpaste             Print the contents of the device's pasteboard to standard output.
	help                Prints the usage for a given subcommand.
	io                  Set up a device IO operation.
	diagnose            Collect diagnostic information and logs.
	logverbose          enable or disable verbose logging for a device
	status_bar          Set or clear status bar overrides
	ui                  Get or Set UI options
	push                Send a simulated push notification
	privacy             Grant, revoke, or reset privacy and permissions
	keychain            Manipulate a device's keychain

--set previews delete all

残りのオプションはおそらく、previewsというpathを指定して、previewsのデータ(キャッシュ?)を全て削除しているという認識。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?