Xcode の Preview がクラッシュしっぱなし。

ストレージまわりの話ではないかと思いながらしらべる。
xcrun simctl -—set previews delete all
👉 Preview keeps crashing | Apple Developer Forums
👉 SwiftUIのプレビューが動かなくなった時の対処方法 #SwiftUI - Qiita
📲 ログから原因を見つける
まずは、見てみますか。
#!/bin/bash
cd ~/Library/Logs/DiagnosticReports
file=$(ls XCPreview* | head -1)
open $file
何か起こったらログ確認大事。
📲 対応方法
いろいろありそうです。
このシミュレータですが、通常のシミュレータとは別でXcodeが持っています。しかしストレージ管理のデベロッパ欄には表示されない上に自動で削除されません。私の環境ではiOS14.1のシミュレータなども残っていました。
👉 【SwiftUI】PreviewのSimulator残留 | thwork
cd ~/Library/Developer/Xcode/UserData/Previews/Simulator\ Devices/
find . -name com.apple.suggestions.plist -exec plutil -replace SuggestionsAppLibraryEnabled -bool NO {} ";"
👉 [Tips]Xcode13.1のSwiftUIのpreviewでCPU使用率が高くなるのをSpotlightを止めて回避する(iOS15) #iOS - Qiita
- Restart the computer and re-run xcrun simctl --set previews delete all
- Delete stored Preview data directly. This data is stored in ~/Library/Developer/Xcode/UserData/Previews.
👉 Use Realm with SwiftUI Previews — Realm
xcrun simctl --set previews delete unavailable | all
👉 SwiftUI Previews - Disk space issue | Apple Developer Forums
Save space by
1. xcrun simctl delete unavailable
2. xcrun simctl erase all
3. Delete /Users/username/Library/Developer/CoreSimulator folder.
👉 swiftui - Xcode 13 UI Previews folder takes too much space - Stack Overflow
📲 xcrun simctl とは ?
コマンドラインツールから help を確認する。
❯ xcrun simctl help
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:
addmedia Add photos, live photos, videos, or contacts to the library of a device.
boot Boot a device or device pair.
clone Clone an existing device.
create Create a new device.
delete Delete specified devices, unavailable devices, or all devices.
diagnose Collect diagnostic information and logs.
erase Erase a device's contents and settings.
get_app_container Print the path of the installed app's container
getenv Print an environment variable from a running device.
help Prints the usage for a given subcommand.
icloud_sync Trigger iCloud sync on a device.
install Install an app on a device.
install_app_data Install an xcappdata package to a device, replacing the current contents of the container.
io Set up a device IO operation.
keychain Manipulate a device's keychain
launch Launch an application by identifier on a device.
list List available devices, device types, runtimes, or device pairs.
location Control a device's simulated location
logverbose enable or disable verbose logging for a device
openurl Open a URL in a device.
pair Create a new watch and phone pair.
pair_activate Set a given pair as active.
pbcopy Copy standard input onto the device pasteboard.
pbpaste Print the contents of the device's pasteboard to standard output.
pbsync Sync the pasteboard content from one pasteboard to another.
privacy Grant, revoke, or reset privacy and permissions
push Send a simulated push notification
rename Rename a device.
runtime Perform operations on runtimes
shutdown Shutdown a device.
spawn Spawn a process by executing a given executable on a device.
status_bar Set or clear status bar overrides
terminate Terminate an application by identifier on a device.
ui Get or Set UI options
uninstall Uninstall an app from a device.
unpair Unpair a watch and phone pair.
upgrade Upgrade a device to a newer runtime.
❯ xcrun simctl help delete
Delete specified devices, unavailable devices, or all devices.
Usage: simctl delete <device> [... <device n>] | unavailable | all
Specifying unavailable will delete devices that are not supported by the current Xcode SDK.
❯ xcrun simctl list devices
== Devices ==
-- iOS 17.0 --
iPhone SE (3rd generation) (EE4D7500-5439-4D41-AD42-6028F649FA44) (Shutdown)
iPhone 15 (984F204F-2D4E-4E56-8EEE-D11C46EDD9C2) (Shutdown)
iPhone 15 Plus (C1349C55-57AC-4E47-9EF3-71A848E24A4E) (Shutdown)
iPhone 15 Pro (04DC04FF-87DB-4EB6-91D8-C8CB4CF10015) (Shutdown)
iPhone 15 Pro Max (5DC11544-4C3E-4852-8899-3D9E0844519B) (Shutdown)
iPad Air (5th generation) (906B44B3-B298-4CF1-A5FB-0B4D43277636) (Shutdown)
iPad (10th generation) (3804C1FA-6306-4CB7-98E0-D24CAFA70537) (Shutdown)
iPad mini (6th generation) (351ED4C6-2DF3-4F1F-A29A-6D44483D9A95) (Shutdown)
iPad Pro (11-inch) (4th generation) (96D48442-96AA-421A-BBA6-6F45EE8ECDBE) (Shutdown)
iPad Pro (12.9-inch) (6th generation) (0B527419-DE2A-4146-93C4-55540B624C5C) (Shutdown)
❯ xcrun simctl --set previews list devices
Using Previews Device Set: '/Users/mao/Library/Developer/Xcode/UserData/Previews/Simulator Devices'
== Devices ==
-- iOS 17.0 --
iPhone 15 Pro (676858D4-35E8-4841-91F4-17804B3E7565) (Shutdown)
覚えておくべきは、
Preview は、シュミレータ単独と別枠でシュミレータを使っている。
ということ。
📲 まとめ
Preview と シュミレーターに関連する問題は多そうです。
- CPU 使用率
- ストレージ占有
- キャッシュ・データ不整合
私の場合スッキリ対応した方法としては、以下を Xcode を一旦終了して実行。
xcrun simctl --set previews delete all
rm -rf ~/Library/Developer/Xcode/UserData/Previews
rm -rf ~/Library/Developer/CoreSimulator/Caches
👉 How to clear/reset SwiftUI Preview Caches?
Behavors に入れときますか、消した previews に関しては自動で作成されると思って良さそう。



![✔[Show logcat automatically]
✔[Clear log before launch]](https://i0.wp.com/android.benigumo.com/wp-content/uploads/2023/10/51ec1c8bc54284c8dde09ff694e855e7.png?ssl=1)
![2023年8月31日以降 アプリは Android 13(API レベル 33)以降を対象にする必要があります。
2023年9月26日
Jetpack Compose Dependency versions API-33 vs API-34
2023年9月23日
メモリーリークを防ぐには欠かせない Lifecycle Observer は remove/unregister 不要
2023年9月10日
Gson が R8 で落ちる
2023年8月28日
【Kotlin DSL】Deprecated な packagingOptions が fun Packaging.() に変換される件
2023年8月27日
【Android】通知が表示されないときのアプリ別の端末設定 ON/OFF ⚙️
2023年8月25日
Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in /app/build/outputs/mapping/debug/missing_rules.txt
2023年8月24日
Unresolved reference: BuildConfig
2023年8月16日
ログインに使っている Twitter (X) アカウントの連携を削除する手順
2023年8月11日
【iPhone】Yahoo天気アプリ 「現在地ボタンが変わりました」は「現在地ボタンは無くなりました」では?
2023年8月10日
【Mac】絵文字 や GitHubショートコード は「GitHub Emoji Picker」で入力する 😀
2023年8月9日
ChatGPT クローラー の UA(ユーザーエージェント) と IPアドレス範囲 まとめ
2023年8月4日
Android OS version market share
2023年7月30日
【iPhone】「パケ詰まり」「パケ止まり」を修復するショートカット 📱
2023年7月26日
Android Studio Giraffe | 2022.3.1 の dependencies の揃え方
2023年7月24日
将来、URL の twitter.com は x.com となるんだろうか。
2023年7月20日
Service Locator と DI どちらを使うか、という話。
2023年7月13日
【iPhone/Android】富士山 にいくなら「富士山」アプリ 🏔
2023年7月12日
Chromecast の 素晴らしい背景画面 をダウンロードできる件
2023年7月11日
スマホスタンド(充電不可)を作ってみたが、まあまあ使っている 📱
2023年7月10日
【Android Studio】[File] - [Project Structure] - [Suggestions] で「Update」する dependencies の妥当性 💉
2023年7月7日
【WordPress】自分のブログで「無効なトラフィック」を発生させないための Adsense タグ記述
【Jetpack Compose】TextField の フォーカス と IME 開閉 と カーソル位置](https://i0.wp.com/android.benigumo.com/wp-content/uploads/2023/10/output.gif?ssl=1)
