swiftui

Unable to Save Picker Result to UserDefaults

时光总嘲笑我的痴心妄想 提交于 2020-11-29 21:20:31
问题 I am trying to save the result of a picker to user defaults. The user default save operation occurs in the class UserData via method saveBase. I have tried a similar technique successfully with a button but my call after the picker gives the famous error: Type '()' cannot conform to view. struct aboutView: View { @EnvironmentObject var userData: UserData @State private var baseEntry: Int = 0 let base = ["Level 1", "Level 2","Level 3","Level 4"] var body: some View { Text("comment") Text(

Unable to Save Picker Result to UserDefaults

折月煮酒 提交于 2020-11-29 21:19:59
问题 I am trying to save the result of a picker to user defaults. The user default save operation occurs in the class UserData via method saveBase. I have tried a similar technique successfully with a button but my call after the picker gives the famous error: Type '()' cannot conform to view. struct aboutView: View { @EnvironmentObject var userData: UserData @State private var baseEntry: Int = 0 let base = ["Level 1", "Level 2","Level 3","Level 4"] var body: some View { Text("comment") Text(

Unable to Save Picker Result to UserDefaults

久未见 提交于 2020-11-29 21:19:04
问题 I am trying to save the result of a picker to user defaults. The user default save operation occurs in the class UserData via method saveBase. I have tried a similar technique successfully with a button but my call after the picker gives the famous error: Type '()' cannot conform to view. struct aboutView: View { @EnvironmentObject var userData: UserData @State private var baseEntry: Int = 0 let base = ["Level 1", "Level 2","Level 3","Level 4"] var body: some View { Text("comment") Text(

SwiftUI Async data fetch in onAppear

ⅰ亾dé卋堺 提交于 2020-11-29 14:39:22
问题 I have class getDataFromDatabase which has func readData() thats read data from Firebase. class getDataFromDatabase : ObservableObject { var arrayWithQuantity = [Int]() var arrayWithTime = [Double]() func readData(completion: @escaping(_ getArray: Array<Int>?,_ getArray: Array<Double>?) -> Void) { let db = Firestore.firestore() db.collection("amounts").getDocuments { (querySnapshot, err) in if let e = err{ print("There's any errors: \(e)") } if err != nil{ print((err?.localizedDescription)!)

SwiftUI Async data fetch in onAppear

坚强是说给别人听的谎言 提交于 2020-11-29 14:32:28
问题 I have class getDataFromDatabase which has func readData() thats read data from Firebase. class getDataFromDatabase : ObservableObject { var arrayWithQuantity = [Int]() var arrayWithTime = [Double]() func readData(completion: @escaping(_ getArray: Array<Int>?,_ getArray: Array<Double>?) -> Void) { let db = Firestore.firestore() db.collection("amounts").getDocuments { (querySnapshot, err) in if let e = err{ print("There's any errors: \(e)") } if err != nil{ print((err?.localizedDescription)!)

SwiftUI Async data fetch in onAppear

大城市里の小女人 提交于 2020-11-29 14:29:51
问题 I have class getDataFromDatabase which has func readData() thats read data from Firebase. class getDataFromDatabase : ObservableObject { var arrayWithQuantity = [Int]() var arrayWithTime = [Double]() func readData(completion: @escaping(_ getArray: Array<Int>?,_ getArray: Array<Double>?) -> Void) { let db = Firestore.firestore() db.collection("amounts").getDocuments { (querySnapshot, err) in if let e = err{ print("There's any errors: \(e)") } if err != nil{ print((err?.localizedDescription)!)

SwiftUI Generic Pull to refresh view

北战南征 提交于 2020-11-29 10:58:32
问题 I have this CustomScrollView which wraps my HomeView and if you pull down it fetches new data. It works fine but the thing is that I want to reuse this in multiple views and I do not want to create a copy of this for each of my views. I have tried to do this var rootView: View but it throws an error saying View is not convertible to HomeView . So there are two thing witch should be generic. HomeView() and HomeViewModel . Any idea how to achieve that? struct CustomScrollView :

SwiftUI Generic Pull to refresh view

送分小仙女□ 提交于 2020-11-29 10:57:53
问题 I have this CustomScrollView which wraps my HomeView and if you pull down it fetches new data. It works fine but the thing is that I want to reuse this in multiple views and I do not want to create a copy of this for each of my views. I have tried to do this var rootView: View but it throws an error saying View is not convertible to HomeView . So there are two thing witch should be generic. HomeView() and HomeViewModel . Any idea how to achieve that? struct CustomScrollView :

Optional Binding in parameter SwiftUI

妖精的绣舞 提交于 2020-11-29 10:40:15
问题 Here are my optional binding @Binding var showSheetModifFile : Bool? @Binding var fileToModify : File? init( showSheetModifFile : Binding<Bool?>? = nil, fileToModify : Binding<File?>? = nil) { _showSheetModifFile = showSheetModifFile ?? Binding.constant(nil) _fileToModify = fileToModify ?? Binding.constant(nil) } So now when I try to call this constructor: @State var showModifFileSheet : Bool? = false @State var fileToModify : File? = File() ... SingleFileView(showSheetModifFile: self.

typealias LazyVStack for iOS 13

别来无恙 提交于 2020-11-29 10:14:23
问题 I have a SwiftUI app that I want to maintain iOS 13 support for, but on iOS 14 I want to use the new LazyVStack and LazyHStack . I was thinking typealias would be perfect for this, but wasn't sure how to properly set this up so the alias is used on iOS 13 but not on 14. I tried this, but believe this would make the alias available on iOS 13 and up, so would include it on iOS 14 too. Is there a way to set the availability to iOS 13 only? Or is there a better way to do this? @available(iOS 13.0