// 获取图片 let uploadImage = UIImage(named: "jiadai"); // 保存文件的名称 let paths = NSSearchPathForDirectoriesInDomains(.DesktopDirectory, .AllDomainsMask, true); /* 前面参数 DesktopDirectory DocumentDirectory DocumentationDirectory */ /* 后面参数 UserDomainMask 保存在沙盒根目录 AllDomainsMask 保存在沙盒的Library路径下 */ let filePath = paths[0] + "jiadai.png"; print("\(filePath)"); // 保存成功会返回true let result = UIImagePNGRepresentation(uploadImage!)?.writeToFile(filePath, atomically: true); print("\(result)");