3

我对 iOS 编程相当陌生,并且正在自学如何使用 Swift。我需要为我为班级制作的应用程序设置地理围栏。我的问题是在初始化 CLCircularRegion 时,我收到一条错误消息,上面写着“使用未声明的类型 'center' ”。我遵循了 Apple 开发者网站上的文档,不知道我做错了什么。任何帮助将不胜感激。谢谢你。

import UIKit
import MapKit
import CoreLocation

class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {

@IBOutlet var mapView: MKMapView!

var manager = CLLocationManager()

@IBAction func startMonitoring(sender: AnyObject) {
    // 43.039278, -87.932479 mccormick hall location
    var latitude:CLLocationDegrees = 43.039278
    var longitude:CLLocationDegrees = -87.932479
    var center:CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitude, longitude)
    var radius:CLLocationDistance = CLLocationDistance(10.0)
    var identifier:String = "vicmic"

    var geoRegion:CLCircularRegion = CLCircularRegion(center: center, radius: radius, identifier: identifier)

}


override func viewDidLoad() {
    super.viewDidLoad()

    // Core Location
    manager.delegate = self
    manager.desiredAccuracy = kCLLocationAccuracyBest
    manager.requestWhenInUseAuthorization()
    manager.startUpdatingLocation()

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


}
4

1 回答 1

1

广义上....代码似乎还可以

1)尝试在类型注释之前留下空格,例如 from var center:CLLocationCoordinate2Dto thisvar center: CLLocationCoordinate2D

2)尝试清理您的 DerivedData,重新启动 Xcode ..

于 2014-11-18T22:56:52.493 回答