2

I made a game where I need to cast the touched SKSpriteNode into a custom class. It works perfectly fine on the iOS 9.1 simulator but it cannot seem to cast at all in the iOS 8.4 simulator.

In iOS 9.1, my class is an MyCustomClass type but in iOS 8.4 it is a SKSpriteNode. Nothing else is changed, only the simulator OS.

I set the custom class directly in Xcode in the SpriteKit GameScene (I click on the node and use the right tab to enter "MyCustomClass" in the "Custom Class" section). I tried adding the project name as in "Project.MyCustomClass" but this has no effect. How I set my custom class in Spritekit Scene

If you have a solution, I would love to know it!

if self.nodeAtPoint(location).isKindOfClass(MyCustomClass) {
    print("Is my class") //This is the result in iOS 9.1
}else if self.nodeAtPoint(location).isKindOfClass(SKSpriteNode){
    print("Is an SKSPriteNode") //This is the result in iOS 8.4
}else if self.nodeAtPoint(location).isKindOfClass(SKNode) {
    print("Is an SKNode")
}

if let touchedNode = self.nodeAtPoint(location) as? Objet {
    //Fails on iOS 8.4 but succeed in iOS 9.1
}

Thanks for your time.

PS: I am using Xcode 7.1.1.

David Gourde
  • 3,709
  • 2
  • 31
  • 65
  • If you are sure that nodeAtPoint(location) type is MyCustomClass, why You need to cast it? – user3441734 Nov 17 '15 at 15:34
  • I only know in this specific test that I did to understand why nothing was working on iOS 8.4. – David Gourde Nov 17 '15 at 15:51
  • 1
    Your 'specific' test is iOS version dependent ... , or better say part of your code is iOS version dependent. The swift statement in your example is NOT – user3441734 Nov 17 '15 at 15:56
  • I changed the question to reflect the tests I've made after you comments. You are right the problem was not the casting but the fact that the Custom Class is not set correctly when the simulator runs in iOS 8.4. – David Gourde Nov 17 '15 at 16:39
  • Does `if let self.nodeAtPoint(location) as? MyCustomClass` fail on 8.4? – MirekE Nov 17 '15 at 16:52
  • It fails on iOS 8.4, but succeed on 9.1. This is my current problem, as none of my cast works in iOS 8.4. I updated this information on the question. – David Gourde Nov 17 '15 at 16:53

1 Answers1

0

Sadly enough, Custom Classes (or Sub Classes) simply do not work on iOS 8.4.

I had to rewrite my logic.

Thanks for your help anyway guys.

David Gourde
  • 3,709
  • 2
  • 31
  • 65