1

I recently read this post regarding passing multiple arguments to an NSStringDrawingOptions property of boundingRectWithSize(), however the marked solution there did not work for me.

Does anybody know of any given solution, or are we still waiting on Apple to iron this bug out of Swift?

The snippet:

options: NSStringDrawingOptions.UsesFontLeading | NSStringDrawingOptions.UsesLineFragmentOrigin

In terms of the thrown error: NSStringDrawingOptions is not convertible to bool

I have tried passing each of the solutions proposed in the cited post, but nothing works for me, any direction on this would be greatly appreciated.

Community
  • 1
  • 1
Halfpint
  • 3,967
  • 9
  • 50
  • 92
  • I don't think it's solvable. Swift is requiring an enum value of type NSStringDrawingOptions but there is no value that represents the combination of other values. Your best bet is probably to write a helper or extension method in Objective-C that you can call from Swift. – Mike Taverne Nov 27 '14 at 02:19
  • Did you try the solution proposed by Alexey Globchastyy in that post you mentioned? – Mike Taverne Nov 27 '14 at 02:20
  • @MikeTaverne yes I did, as you suggested above I believe we are going to have to wait for a patch on SWIFT, thanks anyway :) – Halfpint Nov 29 '14 at 15:30

1 Answers1

1

Use unsafeBitCast.

Like below:

let options = unsafeBitCast(NSStringDrawingOptions.UsesLineFragmentOrigin.rawValue | 
                            NSStringDrawingOptions.UsesFontLeading.rawValue,
                            NSStringDrawingOptions.self)
kishikawa katsumi
  • 10,418
  • 1
  • 41
  • 53