我正在尝试将我的位置发布到 iCloud 数据库。我不断收到“预期声明”错误,我正在尝试修复该错误,但不知道该怎么做。
我的代码如下:
CLGeocoder *geocoder = [CLGeocoder new]
[geocoder geocodeAddressString:artwork[kArtworkAddressKey] completionHandler:^(NSArray *placemark, NSError *error){
if (!error) {
if (placemark.count > 0) {
CLPlacemark *placement = placemark[0]
artworkRecord[kArtworkLocationKey] = placement.location
}
} else {
// insert error handling here
}
// Save the record to the database
}]
我是新手,如果这是一个简单的问题,请原谅。
最佳答案
问题是您已将 Objective-C 放入 Swift 文件中。你可以这样翻译...
objective-c
CLGeocoder *geocoder = [CLGeocoder new]
[geocoder geocodeAddressString:artwork[kArtworkAddressKey] completionHandler:^(NSArray *placemark, NSError *error){
if (!error) {
if (placemark.count > 0) {
CLPlacemark *placement = placemark[0]
artworkRecord[kArtworkLocationKey] = placement.location
}
} else {
// insert error handling here
}
// Save the record to the database
}]
swift ...
let geocode = CLGeocoder()
geocoder.geocodeAddressString(artwork[kArtworkAddressKey]) {
placemark, error in
if error {
// handle error
} else {
if let placement = placemark[0] {
self.artworkRecord[kArtWorkLocationKey] = placement.location
}
}
}
无论如何,类似的事情。
关于swift - 使用 Swift 将位置发布到 iCloud 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28174818/