How to pass multiple enum values as a function parameter

后端 未结 8 1534
余生分开走
余生分开走 2020-11-29 10:04

How would I do the following - passing two NSStringDrawing options as a function parameter in swift:

CGRect boundingRect = [string boundingRectWithSize:CGSiz         


        
相关标签:
8条回答
  • 2020-11-29 10:42

    in swift 2.0 that will be something like

    theStringDrawingOptions = [NSStringDrawingOptions.UsesLineFragmentOrigin,
                               NSStringDrawingOptions.UsesFontLeading]
    

    see lecture wwdc 2015 -> 106_hd_whats_new_in_swift in 6 min

    0 讨论(0)
  • 2020-11-29 10:44

    Another solution, use unsafeBitCast.

    Like below:

    let options = unsafeBitCast(NSStringDrawingOptions.UsesLineFragmentOrigin.rawValue | 
                                NSStringDrawingOptions.UsesFontLeading.rawValue,
                                NSStringDrawingOptions.self)
    
    0 讨论(0)
提交回复
热议问题