作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
<分区>
在 Obj-C 中,我喜欢做这样的事情:
[MyUILib makePathForRectWithEdges:UIRectEdgeLeft|UIRectEdgeRight]
其中的参数是一个 NSInteger,稍后我将其与 UIRectEdge 枚举值进行比较以查看我想在路径中包含哪些边:
if(edges & UIRectEdgeTop)
{
// Draw Stuff
}
在 Swift 中,Apple 将 UIRectEdge 定义为:
struct UIRectEdge : OptionSetType {
init(rawValue rawValue: UInt)
static var None: UIRectEdge { get }
static var Top: UIRectEdge { get }
static var Left: UIRectEdge { get }
static var Bottom: UIRectEdge { get }
static var Right: UIRectEdge { get }
static var All: UIRectEdge { get }
}
我仍然可以使用 UIRectEdge.Top.rawValue
来获取 UInt,但调用的函数如下:makePathForRectWithEdges(UIRectEdge.Left.rawValue|UIRectEdge.Right.rawValue)
与我以前的做法相比,它丑陋且难以阅读。是否有更好的模式来使用标志,或者这就是它在 Swift 中必须采用的方式?
我是一名优秀的程序员,十分优秀!