Cannot call value of non-function type 'CGPoint'

This is the error (Cannot call value of non-function type 'CGPoint') I receive at the call to UIView:point() in the following code:


override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView?

{

if point(inside: point, with: event)

{

gViewCtr.DismissAll()

gViewCtr.fCF_UndoBtn.isEnabled = (gCollector.fWaypoint!.count > 0)

gViewCtr.fCampfireControls.isHidden = false

return self

}

else { return nil }

}


The call to point() to determine whether the receiver contains the argument CGPoint is straight out of the manual.

Does it have something to do with the argument having the same label as the function?

Renaming the argument with a temporary variable does not help, however.


Any help greatly appreciated.

Steve.

Answered by QuinceyMorris in 277409022

Yes, the problem is that "point" is interpreted as the parameter, masking the name of the instance method "point(inside:,with:)". If you want, you can solve it without renaming by making the method receiver explicit:


override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
     if self.point(inside: point, with: event)


or you can rename the parameter:


override func hitTest(_ testPoint: CGPoint, with event: UIEvent?) -> UIView? {
     if point(inside: testPoint, with: event)


Both of those compile without error for me.

Accepted Answer

Yes, the problem is that "point" is interpreted as the parameter, masking the name of the instance method "point(inside:,with:)". If you want, you can solve it without renaming by making the method receiver explicit:


override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
     if self.point(inside: point, with: event)


or you can rename the parameter:


override func hitTest(_ testPoint: CGPoint, with event: UIEvent?) -> UIView? {
     if point(inside: testPoint, with: event)


Both of those compile without error for me.

Awesome. Thanks again, Quincey.

import SwiftUI

struct ContentView: View { var body: some View { Path(){ path in path.move(to: CGPoint(x:30, y:30)) path.addLine(to: CGPoint(x:230, y:30 )) path.addLine(to: CGPoint(x:230, y:150 )) path.addLine(to: CGPoint(x:30, y:150)) } .fill(Color.blue) } }

error Cannot call value of non-function type 'CGPoint'

#Preview { ContentView() }

import SwiftUI

struct ContentView: View {

var body: some View {
        Path(){ path in
            path.move(to: CGPoint(x:30, y:30))
            path.addLine(to: CGPoint(x:230, y:30 ))
            path.addLine(to: CGPoint(x:230, y:150 ))
            path.addLine(to: CGPoint(x:30, y:150))
        }
        .fill(Color.blue)
}

}

#Preview { ContentView() }

import SwiftUI

struct ContentView: View {

var body: some View {
        Path(){ path in
            path.move(to: <#T##CGPoint#>(x:30, y:30))
            path.addLine(to: <#T##CGPoint#>(x:230, y:30 ))
            path.addLine(to: <#T##CGPoint#>(x:230, y:150 ))
            path.addLine(to: <#T##CGPoint#>(x:30, y:150))
        }
        .fill(Color.blue)
}

}

#Preview { ContentView() }

Cannot call value of non-function type 'CGPoint'

Cannot call value of non-function type 'CGPoint'
 
 
Q