Implicitly-unwrapped optionals are such an anti-pattern that they are implicitly converted to other types in Swift 3.
UnsafePointers are a throw back to an old language.
Yet CTFrameGetLineOrigins requires a UnsafeMutablePointer<CGPoint>! .
Leaving a big question, how do I even create an implicitly unwrapped unsafe pointer ?
Obviously, the need to have an unsafe pointer in the first place is an anti-pattern as well. So either I'd want a
var lineOrigins:[CGFloat] //computed property
or
func lineOrigins(inRange:CFRange = default)->[CGFloat]
But, as is, is this basically useless, or am I missing something? I spent an hour trying to figure out how to create the argument, haven't figured it out. Frankly I don't think I should have to.
You should submit a bug report about this. It sort of looks like the underlying CoreText API isn't annotated properly. I think the default for C/Obj-C parameters that don't have a nullability annotation is to be imported with the "!". In effect, in Swift 3 it means that the pointer is optional (although it really can't be, except perhaps in the case when the range is empty).
As to how to write the call, the following compiles for me:
class X
var cf: CTFrame!
func c () {
var o = [CGPoint] (repeating: .zero, count: 1)
CTFrameGetLineOrigins (cf, CFRange (location: 0,length: 1), &o)
}
}I wasn't in a position to see if it crashed at runtime, but it seems to work in many scenarios to use the "&" to get an implicit conversion and avoid the messy syntax details of an explicit conversion.