0

I am currently trying to convert two UILabel variables to Doubles. this is what I am currently trying:

@IBOutlet weak var longitude: UILabel!

@IBOutlet weak var latitude: UILabel!

var longitude_dbl = Double(longitude)
var latitude_dbl = Double(latitude)

Any help would be great.

dan
  • 9,695
  • 1
  • 42
  • 40
  • use longitude.text! and latitude.text! – Yury Jul 12 '16 at 15:26
  • The help is here: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UILabel_Class/#//apple_ref/occ/instp/UILabel/text – Eric Aya Jul 12 '16 at 15:27
  • I've done that and it is giving me a Thread 1 EXC_Breakpoint error and no, i don't have any breakpoints – Chris Masterson Jul 12 '16 at 15:32
  • Then it probably means that your UILabels are not properly hooked in IB. Have a look at this, there's a chapter about your possible issue: http://stackoverflow.com/questions/32170456/what-does-fatal-error-unexpectedly-found-nil-while-unwrapping-an-optional-valu – Eric Aya Jul 12 '16 at 15:37

1 Answers1

1

Try this: First, check if you have the value in your UILabel's text property.

@IBOutlet weak var longitude: UILabel!
@IBOutlet weak var latitude: UILabel!
var longitude_dbl: Double?
var latitude_dbl: Double?

func setCoordinateValues() {
     guard let longitudeValue = longitude.text, latitudeValue = latitude.text else {
        return
    }
    longitude_dbl = Double(longitudeValue)
    latitude_dbl = Double(latitudeValue)
}

Before that make sure, your labels are hooked up properly in the XIB/storyboard.

Santosh
  • 2,900
  • 1
  • 16
  • 16