あぼぼーぼ・ぼーぼぼ

のんびり生きたい

(未解決)既存プロジェクトでXcode PreviewsにUIが表示されないのでワークアラウンドを試している

iOS #2 Advent Calendar 2020

本当は解決したら書こうと思ったのですが、年を越しそうだったので現状のメモとして記しておきます。

環境

  • Xcode12.0
  • Swift5.3
  • .swiftファイルが700程度あるプロジェクト
  • Build PhasesでSwiftLint, swift-formatなどなどをRun Scriptとして動かしてる
  • Deployment Info targetはiOS12以上

事象

Xcode Previewsでプレビューが表示されない

f:id:aboy_perry:20201225110737p:plain

SwiftUIファイルはなんでも良いと思いますがテンプレートから生成後、コンパイルエラー回避でiOS13以降の修正をしています。

import SwiftUI

struct SwiftUIView: View {
    @available(iOS 13.0.0, *)
    var body: some View {
        Text( /*@START_MENU_TOKEN@*/"Hello, World!" /*@END_MENU_TOKEN@*/)
    }
}

struct SwiftUIView_Previews: PreviewProvider {
    @available(iOS 13.0.0, *)
    static var previews: some View {
        SwiftUIView()
    }
}

メモ

エラーとワークアラウンド

Updating took more than 5 seconds

f:id:aboy_perry:20201225113324p:plain

プレビュー表示の際AppDelegateの application(_:didFinishLaunchingWithOptions:) を通るらしいので、たしかに結構処理が書かれていたので中身を起動できる程度にほぼほぼコメントアウト

ref https://koze.hatenablog.jp/entry/2020/03/09/090000


Automatic preview updating paused

f:id:aboy_perry:20201225113601p:plain

Run Scriptが悪さしてるかもとのことなのでBuild PhasesのRun Scriptのうち起動できる範囲(SwiftLintやswift-formatなど)の「For install buids only」にチェック。

ref https://stackoverflow.com/questions/58490010/swiftui-automatic-preview-updating-paused-always


Cannot preview in this file - Connection interrupted: send previewinstances message to agent

なんかfirebase-ios-sdkが悪さしてる説があるのでバージョンアップしてみる(ただ前段でdidFinishLaunchingWithOptionsの処理をコメントアウトした際にFirebaseApp.configure()もコメントアウトされている)。

f:id:aboy_perry:20201225113957p:plain

ref https://developer.apple.com/forums/thread/662370

ref https://github.com/firebase/firebase-ios-sdk/issues/6574


RemoteHumanReadableError: Connection request timed out

f:id:aboy_perry:20201225114059p:plain

よし、ワカラン


いったんフォーラムで見つけた策を試してみる。 Build Active Architecture Only をNOにして、 Excluded Architectures に arm64 を指定。

変わらず。

ref https://developer.apple.com/forums/thread/657913?answerId=628433022#628433022

というわけで未解決です

同じ問題にぶつかったぜ〜という方や、もし「これじゃね?」と知ってる方がいたら情報お待ちしております 🙏