Delete specified file from document directory

I checked your code. It’s working for me. Check any error you are getting using the modified code below – (void)removeImage:(NSString *)filename { NSFileManager *fileManager = [NSFileManager defaultManager]; NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSString *filePath = [documentsPath stringByAppendingPathComponent:filename]; NSError *error; BOOL success = [fileManager removeItemAtPath:filePath error:&error]; if (success) { UIAlertView *removedSuccessFullyAlert = [[UIAlertView … Read more

Save Data to .plist File in Swift

Apparently the file is not in a writable location, so I created it in the documents directory. var paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String var path = paths.stringByAppendingPathComponent(“data.plist”) var fileManager = NSFileManager.defaultManager() if (!(fileManager.fileExistsAtPath(path))) { var bundle : NSString = NSBundle.mainBundle().pathForResource(“data”, ofType: “plist”) fileManager.copyItemAtPath(bundle, toPath: path, error:nil) } data.setObject(object, forKey: “object”) data.writeToFile(path, atomically: true) … Read more

How to find NSDocumentDirectory in Swift?

Apparently, the compiler thinks NSSearchPathDirectory:0 is an array, and of course it expects the type NSSearchPathDirectory instead. Certainly not a helpful error message. But as to the reasons: First, you are confusing the argument names and types. Take a look at the function definition: func NSSearchPathForDirectoriesInDomains( directory: NSSearchPathDirectory, domainMask: NSSearchPathDomainMask, expandTilde: Bool) -> AnyObject[]! directory … Read more