我看了一下Objective-C选项enum NSLayoutFormatOptions
的自动生成的Swift标头:
struct NSLayoutFormatOptions : RawOptionSetType {
init(_ rawValue: UInt)
init(rawValue: UInt)
static var AlignAllLeft: NSLayoutFormatOptions { get }
static var AlignAllRight: NSLayoutFormatOptions { get }
static var AlignAllTop: NSLayoutFormatOptions { get }
static var AlignAllBottom: NSLayoutFormatOptions { get }
static var AlignAllLeading: NSLayoutFormatOptions { get }
static var AlignAllTrailing: NSLayoutFormatOptions { get }
static var AlignAllCenterX: NSLayoutFormatOptions { get }
static var AlignAllCenterY: NSLayoutFormatOptions { get }
static var AlignAllBaseline: NSLayoutFormatOptions { get }
static var AlignAllLastBaseline: NSLayoutFormatOptions { get }
static var AlignAllFirstBaseline: NSLayoutFormatOptions { get }
static var AlignmentMask: NSLayoutFormatOptions { get }
/* choose only one of these three
*/
static var DirectionLeadingToTrailing: NSLayoutFormatOptions { get } // default
static var DirectionLeftToRight: NSLayoutFormatOptions { get }
static var DirectionRightToLeft: NSLayoutFormatOptions { get }
static var DirectionMask: NSLayoutFormatOptions { get }
}
声明静态变量的行上的语法让我感到困惑。它看起来像协议语法,需要每个变量的getter,但这是一个struct
声明。这里发生了什么?
我现在也注意到另一个结构CGSize
:
struct CGSize {
var width: CGFloat
var height: CGFloat
}
extension CGSize {
static var zeroSize: CGSize { get }
init()
init(width: Int, height: Int)
init(width: Double, height: Double)
}
同样,这只发生在static var
上。