NSData writeToFile 方法 returns true 但文件未写入磁盘

NSData writeToFile method returns true but file is not written to the disk

我开发了一个OS X 应用程序,有时需要将一些图片保存到磁盘中。我有一个方法可以做到这一点:

func saveImageAtPath(image: NSImage, path: String)
{
    if let data = image.TIFFRepresentation
    {
        let bitmap = NSBitmapImageRep(data: data)
        let pngImage = bitmap?.representationUsingType(NSBitmapImageFileType.NSPNGFileType, properties: [:])
        
        NSLog("Path : %@", path)
        
        if let _ = pngImage?.writeToFile(path, atomically: false)
        {
            NSLog("Everything should work...")
        }
    }
}

当我尝试保存图像时,似乎一切正常,控制台中显示以下文本:

Path : /Users/myusername/Documents/Pictures/Apps/testPictures/mypicture.png

Everything should work...

一个月前一切正常。 这是我的会议:[​​=13=]

OS X Yosemite 10.10.5 Xcode7.2

如果有人有想法...那就太好了!

提前致谢。

我花了一整天的时间试图弄清楚如何编写 swift 2.0 中建议的修复程序,所以现在我想分享一下我已经开始工作了

do{
    let result = try Bool(pngImage!.writeToFile(filePath, options: NSDataWritingOptions.DataWritingAtomic))
}
catch let error as NSError {
    print(error.localizedDescription)
}

我希望这可以节省一些时间。