0

I'm building a SpriteKit game which will have a lot of animated sprites. I am using TextureAtlases.

SKTextureAtlas is written in ObjectiveC and wrapped in NS_ASSUME_NONNULL_BEGIN - meaning, if a textureAtlas with the appropriate name does not exist, the app will throw an exception. Since I will be having a lot of animations, I expect messing up from time to time and trying to access a texture atlas that I did not, in fact, provide.

I am currently using a workaround that supplies a different textureAtlas in case of textureAtlas.textureNames.isEmpty but is there a way of directly checking the validity of a SKTextureAtlas returned from init(named:)?

green_knight
  • 1,319
  • 14
  • 26
  • the `NS_ASSUME_NONNULL_BEGIN` notation is just shorthand for declaring whether parameter types (and return types) are optionals. hence `init(named:String)` as opposed to `init(named:String?)`. it doesn't govern the internals of the SKTextureAtlas initializer including the population of textures. so i'd say your `isEmpty` solution is the best. – Fault May 24 '23 at 10:57

0 Answers0