Application Support You don’t have permission to save the file

Error Domain=NSCocoaErrorDomain Code=513 "You don’t have permission to save the file “data” in the folder “gamedata”." UserInfo={NSFilePath=file:///var/mobile/Containers/Data/Application/651354D9-30FF-4156-9D31-5F90D92D13C7/Library/Application%20Support/gamedata/data, NSUnderlyingError=0x14010cbf0 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}

do {
            try NSFileManager.defaultManager().createDirectoryAtPath(GameData.filePath, withIntermediateDirectories: true, attributes: nil)
        } catch {
            print(error)
        }

        NSKeyedArchiver.archiveRootObject(GameData.data!, toFile: GameData.filePath)
        print(GameData.filePath)

createDirectoryAtPath will say You don’t have permission

OK, so use URL:

let fileManager = NSFileManager.defaultManager()
        let appSupportPath:[NSURL] = fileManager.URLsForDirectory(.ApplicationSupportDirectory, inDomains: .UserDomainMask)
        let store:NSURL = appSupportPath.first!

        do {
            try NSFileManager.defaultManager().createDirectoryAtURL(store, withIntermediateDirectories: true, attributes: nil)
        } catch {
            print(error)
        }

        NSKeyedArchiver.archiveRootObject(GameData.data!, toFile: GameData.filePath)
        print(GameData.filePath)

SKView please presentScene(nil) or the scene will still here and eat the memory

me design LevelViewController (TableView) -> present -> GameViewController . SKView . Scene

When I dismiss the GameViewController, the scene “update” (onEnterFrame) still running, to prove that the scene has not been killed

And after several time present the GameViewController, the app will lag becoz too many SKScene is running.

So please (self.view as! SKView).presentScene(nil) when GameViewController self.dismissViewControllerAnimated(true, completion: nil)