CLLocationDegrees values can't be in an Array?

I was playing with CLLocationDegrees values--specifically latitude and longitude--and I get an error that says values can't be in an Array. I am working with the latest versions of Swift and Xcode. Any comments would be welcome.

Please show your code (include the related declarations of the properties or local variables) causing your issue.

import UIKit

import MapKit

import CoreLocation

class ViewController: UIViewController {

@IBOutlet var SBMMapView: MKMapView!


override func viewDidLoad() {

super.viewDidLoad()

mapSBM()

}

func mapSBM() {

// The two lines below working with array values getting an "Expected Pattern" error.

let SBMArray = [33.842788, 33.3333333, 33.257651]

let : CLLocationDegrees = SBMArray[0]

//Original code works

let SBMLat: CLLocationDegrees = 33.842788

let SBMLong: CLLocationDegrees = -118.353240

let SBMCoordinate = CLLocationCoordinate2D(latitude: SBMLat, longitude: SBMLong)

let latDelta : CLLocationDegrees = 0.01

let longDelta: CLLocationDegrees = 0.01

let SBMSpan = MKCoordinateSpanMake(latDelta, longDelta)

let SBMRegion = MKCoordinateRegion(center: SBMCoordinate, span:SBMSpan)

SBMMapView.setRegion(SBMRegion, animated: true)

let SBMAnnotation = MKPointAnnotation()

SBMAnnotation.title = "South Bay Mazda"

SBMAnnotation.subtitle = "Torrance CA"

SBMAnnotation.coordinate = SBMCoordinate

SBMMapView.addAnnotation(SBMAnnotation)

}



}

Accepted Answer

I'm not sure what you first tried to tell with "values can't be in an Array.", but the reason where you get "Expected Pattern" is obviously clear.


In Swift, the declaration of let-constant takes this form:

let identifier : declared-type = initializing-expression

(More generally, the part "identifier" can be a "pattern" which is sort of a combination of identifiers, so you got error "Expected Pattern".)


        let : CLLocationDegrees = SBMArray[0]

As you see this line does not have an "identifier", so you get error.


Give it an identifier which holds the result of `SBMArray[0]`.

        let SBMlat0 : CLLocationDegrees = SBMArray[0]

Thanks very much appreciated.

CLLocationDegrees values can't be in an Array?
 
 
Q