I'm trying to port some code to Swift that uses UIFont
and CTFont
, and that (successfully, in Objective-C) uses simple bridged casts to get from one to the other and vice versa.
For example, consider this code (in a UIFontDescriptor category):
UIFont *font = [UIFont fontWithDescriptor:self size:0.0];
NSArray *features = CFBridgingRelease(CTFontCopyFeatures((__bridge CTFontRef)font));
I haven't yet been able to figure out how to express this in Swift in a way that will actually compile. The following at least doesn't:
let font = UIFont(descriptor:self, size: 0.0)
let features = CTFontCopyFeatures(font as CTFont)
Error: 'UIFont' is not convertible to 'CTFont'
UIFont
asAnyObject
and then cast it to CTFont. I think at least the casting should work as every class inherits from AnyObject. – Cologne