gpt4 book ai didi

ios - 在 Swift 中初始化 CLCircularRegion

转载 作者:搜寻专家 更新时间:2023-10-31 23:04:44 24 4
gpt4 key购买 nike

我是 iOS 编程的新手,正在自学如何使用 Swift。我需要为我为类(class)制作的应用程序设置地理围栏。我的问题是在初始化 CLCircularRegion 时我收到一条错误消息“Use of undeclared type '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.
}


}

最佳答案

大体上......代码似乎没问题

1) 尝试在类型注释之前留空格,例如从 var center:CLLocationCoordinate2D 到这个 var center: CLLocationCoordinate2D

2) 尝试清理 DerivedData,重启 Xcode..

关于ios - 在 Swift 中初始化 CLCircularRegion,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27002071/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com