|
I have a form that submits info into coredata. The strings go in fine but the integer is always 0. The code i have is as follows:
I am getting the error message: Value of optional type 'Int16?' must be unwrapped to a value of type 'Int16' If anyone could point me in the right direction, i would be very greatfull. Thanks Adam |
|
cigCnt is optional, and the TextField cannot take an optional.
Will make the error go away and work as intended. If cigCnt needed to be optional, that would need to be addressed. |
|
Assuming that it does need to be optional (because i dont want a preselected value), what steps would i need to take here. Apologies in advance, i am brand new to this. Appreciate your help in advance. |
|
My experience with CoreData and SwiftUI is that the TextField and the NumberFormatter() just doesn't work with Int16. You could cast your value
and set it to 0 if none was entered. |
|
That is still giving me an error unfortunately. Chnaging that line to your suggestion give me the following error on that line.
|
|
Also, would you suggest that Int would be better to use than Int16? Or do they act the same in this scenario? |
|
I came up with that I changed my TextField to a normal textfield without NumberFormatter. Changing the Int16 to Int could help here but I'm not sure with CoreData entities. |
|
In the end i just made it a String and made the keyboard numbers only. Major workaround but at least it lets me continue. Thanks all |
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's all new Paywall Editor allow you to remotely configure your paywall view without any code changes or app updates.
Sponsor Hacking with Swift and reach the world's largest Swift community!
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.