1
我正在看一些自动布局库的代码。在这里面,有一个由UIView的采用了协议:在协议的属性声明中,“get”是什么意思?
extension UIView: Constrainable {}
extension UILayoutGuide: Constrainable {
// LayoutGuide doesn't have baseline anchors, so just use the bottom anchor
public var firstBaselineAnchor: NSLayoutYAxisAnchor {
return bottomAnchor
}
public var lastBaselineAnchor: NSLayoutYAxisAnchor {
return bottomAnchor
}
}
public protocol Constrainable {
var topAnchor: NSLayoutYAxisAnchor { get }
var bottomAnchor: NSLayoutYAxisAnchor { get }
var leftAnchor: NSLayoutXAxisAnchor { get }
var rightAnchor: NSLayoutXAxisAnchor { get }
var leadingAnchor: NSLayoutXAxisAnchor { get }
var trailingAnchor: NSLayoutXAxisAnchor { get }
var centerXAnchor: NSLayoutXAxisAnchor { get }
var centerYAnchor: NSLayoutYAxisAnchor { get }
var widthAnchor: NSLayoutDimension { get }
var heightAnchor: NSLayoutDimension { get }
var firstBaselineAnchor : NSLayoutYAxisAnchor { get }
var lastBaselineAnchor : NSLayoutYAxisAnchor { get }
}
什么是空{ get }
完成?
你在说什么空吸? –
请参阅[Swift编程语言:协议]中的“属性要求”(https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Protocols.html#//apple_ref/doc/uid/) TP40014097-CH25-ID267)。 – Rob
[Swift中协议的只读属性]的可能重复(http://stackoverflow.com/questions/31358518/read-only-properties-of-protocols-in-swift) –