Я пытаюсь преобразовать старое приложение в ObjC в Swift как упражнение для практики и столкнулся с некоторыми проблемами. То, как у меня было это в старом приложении, было создание диспетчера CLLocation, а затем я использовал бы:
manager = [[CLLocationManager alloc]init];
manager.delegate = self;
manager.desiredAccuracy = kCLLocationAccuracyBest;
[manager startUpdatingLocation]
который автоматически вызывается:
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
}
и оттуда я мог извлечь всю необходимую мне информацию. Но быстро, нет автозаполнения этого метода, и я не могу понять, как его воспроизвести. В документации указано, что
startUpdatingLocation()
все равно будет вызываться делегатом, но этого не происходит.
Это то, что у меня есть до сих пор:
import UIKit
import corelocation
class ViewController: UIViewController,CLLocationManagerDelegate{
@IBOutlet var gpsResult : UILabel
var manager:CLLocationManager!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
manager = CLLocationManager()
manager.delegate = self
manager.desiredAccuracy = kCLLocationAccuracyBest
manager.startUpdatingLocation()
}
func locationManager(manager:CLLocationManager, didUpdateLocations locations:AnyObject[]) {
println("locations = \(locations)")
gpsResult.text = "success"
}
}
Любая помощь или указатели на то, где искать, будут оценены. Спасибо.
EDIT: Обновлено из предложений, но все еще не работает
EDIT2: Кажется, есть некоторая ошибка, не позволяющая методу работать должным образом в ViewController