相关疑难解决方法(0)

通过Objective-C中的NSNotificationCenter发送和接收消息?

我试图通过NSNotificationCenterObjective-C 发送和接收消息.但是,我还没有找到任何关于如何做到这一点的例子.你如何通过发送和接收消息NSNotificationCenter

objective-c nsnotificationcenter ios

602
推荐指数
6
解决办法
38万
查看次数

Swift - CLGeocoder reverseGeocodeLocation completionHandler闭包

我正在试图做的是传递CLLocation给函数getPlacemarkFromLocation,然后使用传递CLLocation通过reverseGeocodeLocation设置CLPlacemark?将返回.

我在创建completionHandler闭包时遇到问题reverseGeocodeLocation,它会抛出编译器错误/崩溃:


在斯威夫特,CLGeocodeCompletionHandlerCLGeocodeCompletionHandler = (AnyObject[]!, NSError!) -> Void根据文档AnyObject[]!应该包含CLPlacemark的对象,就像Objective-C的版本.

这是我目前的代码:

class func getPlacemarkFromLocation(location:CLLocation)->CLPlacemark?{
    var g = CLGeocoder()
    var p:CLPlacemark?
    g.reverseGeocodeLocation(location, completionHandler: {
        (placemarks, error) in
        let pm = placemarks as? CLPlacemark[]
        if (pm && pm?.count > 0){
            p = placemarks[0] as? CLPlacemark
        }
    })
    return p?
}
Run Code Online (Sandbox Code Playgroud)

编辑:似乎错误placemarks.countplacemarks没有像数组一样对待.它现在编译,但是当我试图进入p内部时,我只得到零completionHandler.我检查了CLLocation被传递的内容并且它们是有效的. …

mapkit mkmapview cllocation ios swift

22
推荐指数
2
解决办法
3万
查看次数