Nsfilemanager Moveitem Throws Error Code=513

NSFileManager creating folder (Cocoa error 513.)

If you search Google on the error domain NSCocoaErrorDomain you find that the code 513 translates to the error NSFileWriteNoPermissionError.

This provides you with the critical clue for solving this problem:

This is the bundle directory containing the application itself. Because an application must be signed, you must not make changes to the contents of this directory at runtime. Doing so may prevent your application from launching later.

Specifically, you cannot modify the contents of a compiled app's bundle folder. This is because the bundle is the compiled application.

When you eventually distribute the app through the iTunes App Store, the application has a digital signature that validates the contents of the app. This signature is generated at compile time.

If you try to change the bundle after compilation, the app changes and the digital signature is no longer valid. This invalidates the application — who knows what code is in there, right? — and so Apple has set up iOS to throw an error if you try to modify the application.

Instead of writing to the bundle, your app can write to one of three accepted app-specific folders: <Application_Home>/Documents, <Application_Home>/tmp and <Application_Home>/Library/Caches.

Most likely, you will want to write to the <Application_Home>/Documents folder.

These folders are only accessible to your app. No other app can access the contents of these folders. (Likewise, your app cannot access another app's folders.)

You can set up your app to allow the end user to manage access to file data through iTunes, via desktop file sharing support.

Using file manager new directory not working

I think, you should provide the full path of your new directory as like below.

let applicationDocumentsDirectory = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).last!

let fileManager = FileManager.default

do {
try fileManager.createDirectory(atPath: applicationDocumentsDirectory + "/subfolder", withIntermediateDirectories: true, attributes: nil)
}
catch let error as NSError {
print("Ooops! Something went wrong: \(error)")
}

NSFileManager Attributesforitem fails and returns null

You need to convert the NSURL to a path for use with any of the NSFileManager methods that take a string. Do this by calling the path method on the URL.

NSURL *someURL = ... // some file URL
NSString *path = [someURL path]; // convert the file:// URL to a file path
NSDictionary *info = [[NSFileManager defaultManager] attributesOfItemAtPath:path];


Related Topics



Leave a reply



Submit