// n var text: String? // n + n , text 修饰 Color var textColor: UIColor! // pp + n + n, highlighted / Text 修饰 Color var highlightedTextColor: UIColor? // n + prep + n, of lines 修饰 number var numberOfLines: Int // adj + n + n ,readable / content 修饰 Guide var readableContentGuide: UILayoutGuide }
classUIView { var interactions: [UIInteraction] var layoutGuides: [UILayoutGuide] var gestureRecognizers: [UIGestureRecognizer]? var motionEffects: [UIMotionEffect] }
名词或名词短语,基本规则和上一节的普通变量差不多,主要是需要注意复数形式,参照下表。
名词复数规则表格
数字
与普通变量命名规则一样,可以关注几个常用的单词。
1 2 3 4 5
var numberOfLines: Int // n计数,Apple中这个词用得比较多 var count: Int // 最大容量 var capacity: Int
structDouble { // is + adj var isNormal: Bool // is + adj var isSubnormal: Bool // is + n var isZero: Bool }
classUIView { // is + pp var isHidden: Bool // is + 名词短语(adj + n) var isExclusiveTouch: Bool // is + 名词短语 + pp (疑问句) var isUserInteractionEnabled: Bool
}
// Apple Pencil 的一个类 classPKCanvasView { // is + n + adj (疑问句) var isRulerActive: Bool }
以上面的代码为例,Apple框架中有很多Bool变量都是使用is构造,总结下构造方法:
1、is + 表语(adj/n/pp/名词短语)
2、is + 名词短语 + 表语(adj/n/pp/名词短语)构成疑问句
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
classUIView {
// v + 名词短语(adj + n) varhasAmbiguousLayout: Bool // v + 名词短语(n + prep + pp) varclearsContextBeforeDrawing: Bool // v + n varautoresizesSubviews: Bool // v + 名词短语(n + pp + n) classvarrequiresConstraintBasedLayout: Bool }
classUIScrollView { // adv + v + 名词短语(n + n + n) varautomaticallyAdjustsScrollIndicatorInsets: Bool