11

I need to check if a CGPoint is inside a SKSpriteNode.

After a little research, CGPathContainsPoint seems appropriated for my purpose.

if CGPathContainsPoint(my_sprite_path, nil, my_point, false) {

 }

But Xcode alerts me: Use of unresolved identifier CGPathContainsPoint

I tried to import :

import UIKit
import CoreGraphics

I'm using Xcode 8.0 beta 6.

Did I miss anything?

cmii
  • 3,556
  • 8
  • 38
  • 69

1 Answers1

19

As of Swift 3, many Core Graphics functions are now methods on the corresponding type. In your example:

if my_sprite_path.contains(my_point) {

}

For more information see SE-044 Import as member.

Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
  • 1
    Thanks it works. Usually Xcode suggests the new methods in Swift 3. I don't understand why for this one, not :) – cmii Aug 18 '16 at 21:44