I was porting some ObjectiveC
custom UIView
subclasses to Swift
this morning. Wanting to make it more "object oriented", I was following the example of extending CGContext
with methods. E.g.
extension CGContext {
func fillColor(color:UIColor) {
CGContextSetFillColorWithColor(self, color.CGColor)
}
}
Because I was converting the objective C style messages (e.g. -(void) drawOutline: (CGContextRef) cr {...}
) to Swift style ones without paying to much attention (e.g. func drawOutline(cr:CGContextRef) {...}
), I didn't realize at first that I was passing CGContextRef
arguments, but had extended CGContext
(not Ref). But it worked!
What was weirder, was when I changed those CGContextRef
's to just CGContext
's. And it still worked. Not just compiled, but ran and drew correctly. For the fun of it, I changed to extension CGContextRef
. And yet it still continues to work. It's as if Swift is smart enough to boil them down to the same thing. Is it? Or is there something more subtle/cool going on here?