nsfilemanager

iOS Memory issue (ARC) when downloading and saving large ammount of images from server

久未见 提交于 2019-12-03 10:14:51
问题 The following code downloads 700+ images from a server with varying sizes, the issue here is that memory (even with ARC) is never released and eventually a memory warning appears followed by the application exiting. I've tried @autoreleasepool in this method and that didn't seem to work. Also I've tried stopping the for loop at different locations to see if memory is released after it finished, but it isn't. This method is called inside a for loop and receives the image url and short name. It

How to write Dictionary to a file?

我的未来我决定 提交于 2019-12-03 09:07:22
I have a FileHelper class where I've implemented 3 methods whose job is to write a Dictionary contents to a file. Those methods are: func storeDictionary(_ dictionary: Dictionary<String, String>, inFile fileName: String, atDirectory directory: String) -> Bool { let ext = "txt" let filePath = createFile(fileName, withExtension: ext, atDirectory: directory) /**** //If I use this method, file is created and dictionary is saved guard (dictionary as NSDictionary).write(to: filePath!, atomically: true) else { return false } */ guard NSKeyedArchiver.archiveRootObject(dictionary, toFile: (filePath?

How to get the list of directores in NSDocumentDirectory?

梦想的初衷 提交于 2019-12-03 09:06:16
I have created some directories in NSDocumentDirectory as if (![tbxCreateFolder.text isEqualToString:@""]) { NSArray *arrPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectoryStr = [arrPaths objectAtIndex:0]; // Get documents folder NSString *dataPath = [documentsDirectoryStr stringByAppendingPathComponent:[NSString stringWithFormat:@"/%@",tbxCreateFolder.text]]; if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath]){ NSError* error; if([[NSFileManager defaultManager] createDirectoryAtPath:dataPath

iOS - Get sum of filesize in directory

假装没事ソ 提交于 2019-12-03 08:40:55
I have the following code I use to cache photos I load off Flickr in the device's memory: NSURL *urlForPhoto = [FlickrFetcher urlForPhoto:self.photo format:FlickrPhotoFormatLarge]; NSString *rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSString *imagePath = [rootPath stringByAppendingString:[self.photo objectForKey:FLICKR_PHOTO_ID]]; NSData *dataForPhoto; NSError *error = nil; if ([[NSFileManager defaultManager] fileExistsAtPath:imagePath]) { dataForPhoto = [NSData dataWithContentsOfFile:imagePath]; } else { dataForPhoto =

iPhone: NSFilemanager fileExistsAtPath:isDirectory: not working properly?

流过昼夜 提交于 2019-12-03 07:20:29
I'm working on an app for jailbroken iPhones. I'm trying to get only the directories of an folder. so I'm doing this: NSArray *contentOfFolder = [[NSFileManager defaultManager] directoryContentsAtPath:path]; NSLog(@"contentOfFolder: %@", contentOfFolder); directoriesOfFolder = [[NSMutableArray alloc] initWithCapacity:100]; for (NSString *aPath in contentOfFolder) { NSLog(@"apath: %@", aPath); BOOL isDir; if ([[NSFileManager defaultManager] fileExistsAtPath:aPath isDirectory:&isDir] &&isDir) { [directoriesOfFolder addObject:aPath]; NSLog(@"directoriesOfFolder %@", directoriesOfFolder); } }

Get resource URL from project specific path

我怕爱的太早我们不能终老 提交于 2019-12-03 05:53:14
I need to retrieve the URL of a resource contained in my Xcode project through a path that begins in the project's directory (aka mainBundle) So if my specified path if ./snd/archer/acknowledge1.wav, I need to create a URL from that. I know I can use NSURL(fileURLWithPath:) for system directories, but I don't know how to do this directly from the bundle. Wain You would use one of the bundle resourse URL methods [[NSBundle mainBundle] URLForResource:@"acknowledge1" withExtension:@"wav" subdirectory:@"snd/archer"]; NSBundle.mainBundle().URLForResource("acknowledge1", withExtension:"wav"

iphone - how to check if the file is a directory , audio , video or image?

左心房为你撑大大i 提交于 2019-12-03 04:13:53
问题 Following my program shows contents of Documents directory and is displayed in a tableView . But the Documents directory contains some directories , some audio , some video , and some images etc . NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *docsDir = [dirPaths objectAtIndex:0]; fileType = @"" ; NSString *subDirectoryPath = [docsDir stringByAppendingPathComponent:fileType]; NSLog(@"path : %@",subDirectoryPath); files = [

iPhone/iPad: Unable to copy folder from NSBundle to NSDocumentDirectory

自古美人都是妖i 提交于 2019-12-03 03:57:02
I am trying to copy a folder in my NSBundle which contains quite a number of images. I tried doing it with these codes. NSFileManager *fileManager = [NSFileManager defaultManager]; NSError *error; NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *documentDBFolderPath = [documentsDirectory stringByAppendingPathComponent:@"Images"]; NSString *resourceDBFolderPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Images"]; [fileManager copyItemAtPath

How to check whether a file is locked in Cocoa?

旧时模样 提交于 2019-12-03 03:50:18
Is there any API to check whether a file is a locked? I am not able to find any API in the NSFileManager class.Let me know if there is any API to check the lock of the file. I found the following link related to file lock http://lists.apple.com/archives/cocoa-dev/2006/Nov/msg01399.html I can invoke – isWritableFileAtPath: on file. Is there any other way to find whether a file is locked? Following Code worked for me. NSError * error; NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:&error]; BOOL isLocked = [[attributes objectForKey:@

File access in a sandboxed Mac app with swift

ぐ巨炮叔叔 提交于 2019-12-03 03:10:47
I am working on an app for OS X 10.9 with swift, sandboxed. The app needs access to a SQLite database file. I let the user choose/open a file with NSOpenPanel. I then save the file path with NSUserDefaults for later use. I want this file to be opened automatically every time when the app is started again. I get the stored path from the NSUserDefault, but when I open the file with this path I get an error, saying I have no permission to access the file. (it is working without sandboxing) It looks like bookmark's are the solution to my problem. Is there a good tutorial how to use bookmark's with