Search code examples
swiftsprite-kitparticles

Swift and Sprite Kit - unarchiving a particle emitter (sks) file


I am getting an error for this block of code:

_bloodEmitter = NSKeyedUnarchiver.unarchiveObjectWithFile(NSBundle.mainBundle().pathForResource("Blood", ofType:"sks"));

The error I get is: "Could not find an overload for 'pathForResource' that excepts the supplied arguments"

The documentation reads:

func pathForResource(_ name: String?,
          ofType extension: String?) -> String?

Why am I getting this error?


Solution

  • Try unwrapping the filePath:

    _bloodEmitter = NSKeyedUnarchiver.unarchiveObjectWithFile(NSBundle.mainBundle().pathForResource("Blood", ofType: "sks")!)