So I have this routine that sets different text uilabel.text values
self.addressLabel.text = firstObject["ADDRESS"] as? String
self.phoneLabel.text = firstObject["PhoneNums"] as? String
self.latitude.text = firstObject["LAT"] as? String
self.longitude.text = firstObject["LON"] as? String
but when I try to print out
println("\(latitude.text!)")
It outputs:
Label
How can I make it so that the println statement prints the string "38.1848392". Thanks!
You can't cast a Double
to String
as it will always fail.
self.latitude.text = 38.1848392 as? String // this will always fail
self.latitude.text = String(format:"%f", 38.1848392) // instead, you have to do it this way
You can set the string to a variable, and then print that.
So:
var latitudeString : String = self.latitude.text
println(latitudeString)
Edit:
Seems like casting the latitude as a String is not properly happening. What you could do is the following:
var lat : Float = firstObject["LAT"] as! Float
var latString = String(lat)
self.latitude.text = latString
println(latString)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.