I have the following code in my project in Xcode 8.3.3 (Swift 3.1):
let font = CGFont(provider!) CTFontManagerRegisterGraphicsFont(font, &error) But in Xcode 9 Beta (Swift 4), I get the following error:
Value of optional type 'CGFont?' not unwrapped; did you mean to use '!' or '?'?
The error is because the initializer for CGFont that takes a CGDataProvider now returns an optional.
But when I apply the fix of:
let font = CGFont(provider) CTFontManagerRegisterGraphicsFont(font!, &error) The code no longer compiles in Xcode 8.3.3 with Swift 3.1 since font is not an optional and thus doesn't play nicely with the !.
Is there a way to make this work in both versions of Xcode? Is Swift 4 supposed to be backwards compatible (compile with Swift 3 compiler)?