Fanny Darmer
Fanny Darmer

Reputation: 29

Best way to store / retrieve this data in IOS ( a single word and a path to a file )

I know there are probably many ways to do this.

I am wondering what direction I should look into for this. I need speed and ease of use. I'm going to guess go with an associative array. But interested in what the seasoned ios developers have to say on it.

basically it will be about 50-200 items. No more than that. Each item containing a single word and a path to a file. ( note that details of the file will be processed / incorporated into the app at runtime ).

Upvotes: 0

Views: 115

Answers (3)

Florian Burel
Florian Burel

Reputation: 3456

It just depends on how your data maters to your app: If it is just data supporting your app, you can easily make them and store them into the preference of your app:

NSDictionary * allUrls = @{ @"aString":@"a/path/to/a/file", @"string2" : @"url2" ...}

NSUserDefaults * preferences = [NSUserDefaults standardUserDefaults];

[preferences setObject:allUrls forKey:@"ALL URLS"];

Then to retrieve it from anywhere in your app :

NSUserDefaults * preferences = [NSUserDefaults standardUserDefaults];

NSDictionary * allUrls = [preferences objectForKey:@"ALL URLS"];

Upvotes: 1

Grzegorz Krukowski
Grzegorz Krukowski

Reputation: 19802

200 NSStrings - don't bother with anything more than just writeToFile: and initWithContentsOfFile: methods to read /write your NSDictionary. All other solution like CoreData sounds too heavy for your needs.

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  
NSString *documentsPath = [paths objectAtIndex:0];
NSString *filename = [documentsPath stringByAppendingPathComponent:@"yourfile.plist"]; 

//write to file
[yourdictionary writeToFile:filename atomically:YES];

//load from file
NSMutableDictionary *loadedDictonary = [[NSMutableDictionary alloc] initWithContentsOfFile:filename];

Upvotes: 1

matt
matt

Reputation: 535017

The word is a string. The path is a string. The pairing between word and path is a dictionary. NSDictionary can write itself to and read itself from a file. Done. You won't even need to "process" anything: the file will simply spring to life as an NSDictionary, ready for use.

Upvotes: 1

Related Questions