swift - Variable was never mutated -
i've been following app tutorial of making simple temp conversion app,
i have these lines of code shown below
// users imput : c var celsius:int = celsiusvalue.text.toint()! //formula : c f // 5f = 9c + 160 // output : f var fah:int = ( 9 * celsius + 160 ) / 5 print(fah) i'm getting couple of errors don't understand why is,
'string' not have member named 'int'
which mean int not able use there no integer in string shown?
value of optional type 'string?' not unwrapped; did mean use '!' or '?'?
i have changed code
var celsius:int = celsiusvalue.text!.toint()! as shows in error helper thing still gives me same error
value of optional type 'string?' not unwrapped; did mean use '!' or '?'?
so i'm confused it, i've read other threads regarding variable never mutated hasn't seemed me what's happening
too long comment...
"variable never mutated" not fatal error in swift. more guideline, , annoying one. each time create new variable that, because haven't yet mutated it. xcode wants write non mutating stuff constants let.
value of optional type 'string?' not unwrapped; did mean use '!' or '?'? important one, , can find thousands of questions on so. swift has optionals, meaning can hold value or can hold nothing @ all. nil. can lead errors , why use "!" , "?". if declare or unwrap "!" result handled wasn't optional. might still nil, not checked nil. if want keep more fuzzy, use "?" way xcode keep warning you working optional.
but more on , how write code optionals can found through google/so.
as string => int. if remember correctly , works nsstrings. make sure nsstring there. else have cast nsstring.
Comments
Post a Comment