Swift, Convert String To Double Error -


i wrote code convert string double gives error :

cannot convert expression's type 'double' type 'nsstring'

and code :

var first = previewlable.text var second = label1.text  var number1: double = (first nsstring).doublevalue var number2: double = (second nsstring).doublevalue 

what have fix error ???

thanks

you need unwrap this:

var number1: double = (first! nsstring).doublevalue var number2: double = (second! nsstring).doublevalue 

or can use way safe:

if let first = previewlable.text, second = lable1.text{     var number1: double = (first nsstring).doublevalue     var number2: double = (second nsstring).doublevalue } 

and info ? , ! read this.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -