|
Is anyone else getting an error for the TextField .keyboardType(.decimalPad)? I keep getting 2 errors: Cannot infer contextual base in reference to member 'numberPad' Value of type 'TextField<Text>' has no member 'keyboardType' which I think is weird because I'm pretty sure that Text field does have keyboardTypes as an imput type. `import SwiftUI struct AddView: View { @State private var name = "" @State private var type = "Personal" @State private var amount = 0.0
} } struct AddView_Previews: PreviewProvider { static var previews: some View { AddView() } }` |
|
I copied and paste your code and it compiled and ran correctly with no errors.
|
|
Other errors: I am also getting an error in the Picker aftert Text($0): Cannot infer contextual base in reference to member 'numberPad' and after @ObservedObject var expense = Expenses: Type 'Expenses.Type' cannot conform to 'ObservableObject'
|
|
try
instead of
You're not creating a new instance, you're refering to the one you already created in ContentView and if you were creating a new instance of Expenses you would need Expenses() plus, these two don't match:
you have expense up at top and expenses in the previews Using:
should fix that. |
|
I don't understand why it would compile for you but not for me. I am running Xcode Version 13.3 (13E113). Are you running an older version? and my code is not compatible with the newer version? Also, I changed "@ObservedObject var expense: Expenses" to "@ObservedObject var expenses: Expenses", but I'm still getting the same error. |
|
Here's my old one I pulled from backup with your modified AddView added. Xcode 13.3 13E113, complies and runs. You should be able to create a new test app, copy and paste all the code below over the ContentView content and be able to build and run it. If you've verified that works then you can compare your original one with this version.
|
|
=..( So frustrating. I copied all of the code that you gave into my Xcode, (after getting 3 errors to add "if #available(macOS 12.0, ) { AddView(expenses: Expenses()) } else {" and adding those) but it's still giving me the error "Cannot infer contextual base in reference to member 'numberPad' " and "Value of type 'TextField<Text>' has no member 'keyboardType' " in the Amount TextField. I don't know what to do when it works for others but not in mine. |
|
The only other thing I can think to suggest is to start a new app from scratch and slowly rebuild the code a little bit at a time. Do a CMD+B frequently to make sure it's building as you go. If it fails to build at some point then undo whatever changes you made and build again to see if you can figure out what's causing the problem. |
|
I agree with Vince. Start from scratch. Also, I went throught the 100 Days tutorials always with iOS in mind. There may be some shennanigans going on with your code and certain Targets? Not sure I know how this magic works. This next part may be nonsense. But if you're adding code like |
|
I just realized that there is an option when creating a new project to change what platform you are coding for. And there is a way to change from macOS to iOS at the top of the window. Looks like that fixed it. Thanks!! |
SAVE 50% To celebrate WWDC23, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.