Get Nil when retrieving file path form Main Bundle when file is in Copy Bundle

55 views Asked by At

Have spent hours debugging this to no avail.

I am trying to add a SKEMitterNode to my scene but when I try to retrieve the path form MainBundle I get:

unexpectedly found nil while unwrapping an Optional value

I have checked the Copy Bundle and the sks file is there:

Copy Bundle

The first path is found no issues, its the second and third that return nil (third code not posted):

if let sparkPath = NSBundle.mainBundle().pathForResource("Spark", ofType: "sks") {

        let spark = NSKeyedUnarchiver.unarchiveObjectWithFile(sparkPath) as! SKEmitterNode;
        spark.position = CGPointMake(CGFloat(x1), CGFloat(y1));
        spark.zPosition = 150;
        gs.overlayGUI.addChild(spark);

    }else{
        print("Cent foin path : ");
    }


    if let sparkPath2 = NSBundle.mainBundle().pathForResource("Spark2a", ofType: "sks'"){

        let spark2 = NSKeyedUnarchiver.unarchiveObjectWithFile(sparkPath2)  as! SKEmitterNode!
        spark2.position = CGPointMake(CGFloat(x2), CGFloat(y2));
        spark2.zPosition = 150;
        gs.overlayGUI.addChild(spark2);

    } else{
        print("Cant find path ");
    }

Any input appreciated.

0

There are 0 answers