【发布时间】:2015-11-05 14:04:47
【问题描述】:
使用 Xcode 7 beta 5,以下代码:
public func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView?
{
guard let title: String = annotation.title else // compile error
{
return nil
}
...
...编译时出现错误“Value of optional type 'String?'没有打开;你是不是要使用“!”或'?'?“。 MKAnnotation 是一个带有可选字符串的协议:
public protocol MKAnnotation : NSObjectProtocol {
...
optional public var title: String? { get }
...
}
这可能很明显,但我看不出有什么问题。你有看到? 谢谢。
编辑:我不相信它是“Value of optional type String? not unwrapped”的副本,因为在后一种情况下没有暂定的可选绑定。
【问题讨论】:
-
奇怪。你可以使用可选绑定而不是保护语句并让它工作吗?
-
我在使用保护之前使用了带有“if let”的可选绑定,同样的问题。
标签: swift