実現したいこと
cannot preview in this file
と表示されConvasが表示されません。
Buildは成功しています。
また、警告は下記5つが出力されています。
・Run script build phase 'Create Symlinks to Header Folders' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. ・Run script build phase 'Create Symlinks to Header Folders' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. ・Run script build phase 'Create Symlinks to Header Folders' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. ・Run script build phase 'Create Symlinks to Header Folders' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. ・Run script build phase 'Create Symlinks to Header Folders' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase.
該当のソースコード
MessageAppApp.swift
1// 2// MessageAppApp.swift 3// MessageApp 4// 5// Created by hashimo ryoya on 2023/04/13. 6// 7 8import SwiftUI 9import FirebaseCore 10// 追加 11class AppDelegate: NSObject, UIApplicationDelegate { 12 func application(_ application: UIApplication, 13 didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { 14 FirebaseApp.configure() 15 return true 16 } 17} 18 19@main 20struct MessageAppApp: App { 21 @UIApplicationDelegateAdaptor(AppDelegate.self) var delegate 22 var body: some Scene { 23 WindowGroup { 24 ContentView() 25 } 26 } 27} 28
ContentView.swift
1// 2// ContentView.swift 3// MessageApp 4// 5// Created by hashimo ryoya on 2023/04/13. 6// 7 8import SwiftUI 9import FirebaseDatabase 10 11struct ContentView: View { 12 @State private var message: String = "" 13 @State private var messages: [String] = [] 14 15 private let ref = Database.database().reference().child("messages") 16 17 var body: some View { 18 VStack { 19 List(messages, id: \.self) { message in 20 Text(message) 21 } 22 23 HStack { 24 TextField("Message", text: $message) 25 .textFieldStyle(RoundedBorderTextFieldStyle()) 26 27 Button("Send") { 28 sendMessage() 29 } 30 .padding(.leading) 31 } 32 .padding() 33 } 34 .onAppear { 35 observeMessages() 36 } 37 } 38 39 private func observeMessages() { 40 ref.observe(.value) { snapshot in 41 var messages: [String] = [] 42 for child in snapshot.children { 43 if let snapshot = child as? DataSnapshot, 44 let message = snapshot.value as? String { 45 messages.append(message) 46 } 47 } 48 self.messages = messages.reversed() 49 } 50 } 51 52 private func sendMessage() { 53 ref.childByAutoId().setValue(message) 54 message = "" 55 } 56} 57 58struct ContentView_Previews: PreviewProvider { 59 static var previews: some View { 60 ContentView() 61 } 62} 63
試したこと
Xcodeの再起動を行ったのですが解決しませんでした。
補足情報(FW/ツールのバージョンなど)
swift-driver version: 1.75.2
Xcode 14.3
Build version 14E222b
回答1件
あなたの回答
tips
プレビュー