Search code examples
iosswiftsprite-kitswift3gameplay-kit

Value of type 'GKEntity' has no member 'componentForClass'. why I can`t find this method in swift 3.0?


I'm trying to run this line:

guard let spriteComponent = entity?.componentForClass(SpriteComponent.self) else {
   return
}

and receiving this:

Value of type 'GKEntity' has no member 'componentForClass'

Apparently apple has removed this method from GamePlayKit GkEntity class. So which method should I use instead?


Solution

  • In Swift 3 this has changed to component(ofType:). So your expression will look like;

    guard let spriteComponent = entity?.component(ofType: SpriteComponent.self) else {
       return
    }