3

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?

Janmenjaya
  • 4,149
  • 1
  • 23
  • 43
Sanf0rd
  • 3,644
  • 2
  • 20
  • 29

1 Answers1

5

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
}
Mark Brownsword
  • 2,287
  • 2
  • 14
  • 23