Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting error: Use of unresolved identifier 'NSRectFill', but __NSRectFill works, why?

Tags:

xcode

swift

I'm new to Swift 4, coding in Xcode 9. Trying to create a very simple MacOS drawing app just to learn a bit more about Swift. I copied some very simple tutorial code, but are getting an error "Use of unresolved identifier 'NSRectFill'. I noticed that the compiler hinted that I use __NSRectFill and this worked...but why? Am I doing some wrong?

import Cocoa

class GraphView: NSView {

    override func draw(_ dirtyRect: NSRect) {
        super.draw(dirtyRect)

        NSColor.white.setFill()
        NSRectFill(bounds)
    }
}
like image 942
ObieeOneKenobee Avatar asked Oct 29 '17 23:10

ObieeOneKenobee


1 Answers

Starting in Swift 3, NSRectFill has been made a method of NSRect / CGRect. So you should have called bounds.fill() instead.

Deep down though, it may still relies on some Core Foundation routines like __NSRectFill. It's better that you avoid those double-underscored functions since they are low-level system stuffs that are poorly documented (at least publicly).

like image 78
Code Different Avatar answered Oct 10 '22 05:10

Code Different