如何将多个枚举值作为函数参数传递
我该怎么做-在swift中传递两个NSStringDrawing选项作为函数参数:
CGRect boundingRect = [string boundingRectWithSize:CGSizeMake(280.0, NSIntegerMax) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
attributes:options context:nil];
回答:
编辑:在 :
let options: NSStringDrawingOptions = [.usesLineFragmentOrigin, .usesFontLeading]
编辑: :
let options: NSStringDrawingOptions = [.UsesLineFragmentOrigin, .UsesFontLeading]
编辑: :
- 从:
enum NSStringDrawingOptions : Int
- 至:
struct NSStringDrawingOptions : RawOptionSetType
您现在可以编写:
let options : NSStringDrawingOptions = .UsesLineFragmentOrigin | .UsesFontLeading
经过一番研究和@Anton Tcholakov的“评论”:
如果您以OS X 10.10为目标,这是这样做的简单方法:
let size = CGSize(width: 280, height: Int.max)
let options : NSStringDrawingOptions = .UsesLineFragmentOrigin | .UsesFontLeading
let boundingRect = string.bridgeToObjectiveC().boundingRectWithSize(size, options: options, attributes: attributes, context: nil)
但是,在iOS 8 SDK(在当前种子中)中,存在一个错误,该错误
NSStringDrawingOptions
将移植为Swiftenum : Int
而不是struct : RawOptionSet
。您应该向Apple发送错误报告,说明此严重问题。
以上是 如何将多个枚举值作为函数参数传递 的全部内容, 来源链接: utcz.com/qa/423150.html