Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift: Converting NSNumber into NSString (NSNumber is not a subtype of NSString)

In my app, I'm going into CoreData and grabbing an entry whose type is a Double, then I'm trying to put that value into a text field in my app.

This looks like

lengthTextField.text = lastSession.length but I'm getting the error NSNumber is not a subtype of NSString

The value of lastSession.length is 6.0 for reference. Any suggestions on how to properly put that data in my text field?

Thanks!

like image 432
Zack Shapiro Avatar asked Dec 17 '14 21:12

Zack Shapiro


1 Answers

In core data numbers are backed by NSNumber. You can view the documentation here

In swift you can access the string representation of the number through the instance property stringValue

lengthTextField.text = lastSession.length.stringValue
like image 97
Freddy Avatar answered Nov 14 '22 06:11

Freddy