Swift Move file to Shared App Container reduces file size -
i attempting copy file bundled app shared app container. seems when use .write method drastically reduces file size , corrupts file. doing incorrectly in write method?
let sharedcontainerurl = nsfilemanager.defaultmanager().containerurlforsecurityapplicationgroupidentifier("group.com.sharedbasemap")! let fileurl = sharedcontainerurl.urlbyappendingpathcomponent("locallayer.tpk") var tpkfile = nsbundle.mainbundle().pathforresource("locallayer", oftype: "tpk") print(sizeforlocalfilepath(tpkfile!)) // returns 3694906 if !nsfilemanager.defaultmanager().fileexistsatpath(fileurl!.path!) { { try tpkfile!.write(fileurl!.path!) print("file saved: \(fileurl)") } catch { print("error saving file") } } else { print("file exists @ \(fileurl)") } print(sizeforlocalfilepath(fileurl!.path!)) // returns 102 func sizeforlocalfilepath(filepath:string) -> uint64 { { let fileattributes = try nsfilemanager.defaultmanager().attributesofitematpath(filepath) if let filesize = fileattributes[nsfilesize] { return (filesize as! nsnumber).unsignedlonglongvalue } else { print("failed size attribute path: \(filepath)") } } catch { print("failed file attributes local path: \(filepath) error: \(error)") } return 0 }
Comments
Post a Comment