【发布时间】:2018-01-10 19:59:38
【问题描述】:
我刚刚开始使用 Swift。有人可以向我解释为什么我可以将数组作为参数传递(byRoundingCorners :)
UIBezierPath(
roundedRect: self.bounds,
byRoundingCorners: [.topLeft, .bottomLeft],
cornerRadii: CGSize(width: radius, height: radius))
但是在变量中传递它会产生错误
var corners = [UIRectCorner.topLeft, UIRectCorner.bottomLeft]
let path = UIBezierPath(
roundedRect: self.bounds,
byRoundingCorners: corners,
cornerRadii: CGSize(width: radius, height: radius))
“无法将 '[UIRectCorner]' 类型的值转换为预期的参数类型 'UIRectCorner'”
【问题讨论】:
-
已经有足够的答案了,但有人可能会补充说 OptionSet(间接)从 ExpressibleByArrayLiteral 继承,这就是允许在初始化中传递文字数组的原因。