@available 预可用 iOS 版本 - 缺少属性
@available with pre-available iOS versions - missing properties
我已经实现了这样的 class:
class MapLayoutGuide: NSObject, UILayoutSupport {
var insetLength: CGFloat = 0
init(insetLength: CGFloat) {
self.insetLength = insetLength
}
var length: CGFloat {
return insetLength
}
}
一切正常,但是新 iOS 版本引入了新的变化:Apple changelog。
所以现在我收到 3 个错误:
Protocol requires property 'topAnchor' with type 'NSLayoutYAxisAnchor'
,
Protocol requires property 'bottomAnchor' with type 'NSLayoutYAxisAnchor'
,
Protocol requires property 'heightAnchor' with type 'NSLayoutDimension'
.
查看 UILayoutSupport
实现,我可以看到新变量:
@available(iOS 9.0, *)
var topAnchor: NSLayoutYAxisAnchor { get }
@available(iOS 9.0, *)
var bottomAnchor: NSLayoutYAxisAnchor { get }
@available(iOS 9.0, *)
var heightAnchor: NSLayoutDimension { get }
我的应用是 iOS 8.0+
。所以问题是我应该如何处理这些值..?我无法设置 @available
标志,我希望代码与 iOS 8
和 9
一起工作,但我必须覆盖它。不知道如何处理它。
昨天在 Xcode Beta 1
上运行的代码,什么 ofc 并不重要,因为我希望它在当前 API 上运行,而不是以前的。
清理项目后成功了。
@available(iOS 9.0, *)
var topAnchor: NSLayoutYAxisAnchor {
return NSLayoutYAxisAnchor()
}
@available(iOS 9.0, *)
var bottomAnchor: NSLayoutYAxisAnchor {
return NSLayoutYAxisAnchor()
}
@available(iOS 9.0, *)
var heightAnchor: NSLayoutDimension {
return NSLayoutDimension()
}
我已经实现了这样的 class:
class MapLayoutGuide: NSObject, UILayoutSupport {
var insetLength: CGFloat = 0
init(insetLength: CGFloat) {
self.insetLength = insetLength
}
var length: CGFloat {
return insetLength
}
}
一切正常,但是新 iOS 版本引入了新的变化:Apple changelog。
所以现在我收到 3 个错误:
Protocol requires property 'topAnchor' with type 'NSLayoutYAxisAnchor'
,Protocol requires property 'bottomAnchor' with type 'NSLayoutYAxisAnchor'
,Protocol requires property 'heightAnchor' with type 'NSLayoutDimension'
.
查看 UILayoutSupport
实现,我可以看到新变量:
@available(iOS 9.0, *)
var topAnchor: NSLayoutYAxisAnchor { get }
@available(iOS 9.0, *)
var bottomAnchor: NSLayoutYAxisAnchor { get }
@available(iOS 9.0, *)
var heightAnchor: NSLayoutDimension { get }
我的应用是 iOS 8.0+
。所以问题是我应该如何处理这些值..?我无法设置 @available
标志,我希望代码与 iOS 8
和 9
一起工作,但我必须覆盖它。不知道如何处理它。
昨天在 Xcode Beta 1
上运行的代码,什么 ofc 并不重要,因为我希望它在当前 API 上运行,而不是以前的。
清理项目后成功了。
@available(iOS 9.0, *)
var topAnchor: NSLayoutYAxisAnchor {
return NSLayoutYAxisAnchor()
}
@available(iOS 9.0, *)
var bottomAnchor: NSLayoutYAxisAnchor {
return NSLayoutYAxisAnchor()
}
@available(iOS 9.0, *)
var heightAnchor: NSLayoutDimension {
return NSLayoutDimension()
}