SwiftとFirebaseFirestoreを用いて入力したタスク(task)をFirestoreのデータベースに送信する機能を作っています。
以下の部分に以下の3つエラーが出て先に進めなくなりました。
swiftUIContentviewswift
1 VStack { 2 TextField("Enter task", text: $title,
エラ〜メッセージ
1、
Static method 'buildBlock' requires that 'RoundedBorderTextFieldStyle' conform to 'View'
2、
Type '(_) -> some View' cannot conform to 'View'; only struct/enum/class types can conform to protocols
3、
Generic parameter 'S' could not be inferred
swiftUI初心者です。しょうもないご質問で恐縮ですがご教示いただけると幸いです。
以下が全コードです。
swiftUIContentviewswift
1import SwiftUI 2import Firebase 3import FirebaseFirestore 4 5 6struct ContentView: View { 7 8 @State private var title: String = "" 9 10 var db = Firestore.firestore() 11 12 private func saveTask() { 13 14 //save the task to the Firebase database 15 db.collection("tasks").addDocument(data: ["title":title]) 16 {error in 17 if let error = error { 18 print(error) 19 } else { 20 print("data is inserted!") 21 } 22 23 } 24 25 } 26 27 var body: some View { 28 VStack { 29 TextField("Enter task", text: $title, 30 onEditingChanged: { _ in }, onCommit:{ 31 self.saveTask() 32 }) 33 .textFieldStyle 34 (RoundedBorderTextFieldStyle()) 35 Spacer() 36 }.padding() 37 } 38} 39 40struct ContentView_Previews: PreviewProvider { 41 static var previews: some View { 42 ContentView() 43 } 44} 45
AppDelegateswift
1import UIKit 2import Firebase 3import FirebaseCore 4 5@main 6class AppDelegate: UIResponder, UIApplicationDelegate { 7 8 9 10 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 11 // Override point for customization after application launch. 12 13 FirebaseApp.configure() 14 15 return true 16 } 17 18 // MARK: UISceneSession Lifecycle 19 20 func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { 21 // Called when a new scene session is being created. 22 // Use this method to select a configuration to create the new scene with. 23 return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) 24 } 25 26 func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) { 27 // Called when the user discards a scene session. 28 // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. 29 // Use this method to release any resources that were specific to the discarded scenes, as they will not return. 30 } 31 32 33}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/12/10 21:32