NSString *strBundle = [[NSBundle mainBundle] pathForResource:@"MyCsvFile" ofType:@"csv"];
NSString *fileObj = [NSString stringWithContentsOfFile:strBundle
encoding:NSUTF8StringEncoding
error:nil];
NSArray *objectArray = [fileObj componentsSeparatedByString:@"\n"];
NSLog(@"%@", objectArray);
NSMutableDictionary *dataDictionary = [[NSMutableDictionary alloc] init];
for (int i = 0; i < [objectArray count]; i++) {
NSArray *tempObj = [[objectArray objectAtIndex:i] componentsSeparatedByString:@","];
if (i != [objectArray count] - 1) {
[dataDictionary setValue:[tempObj objectAtIndex:1] forKey:[tempObj objectAtIndex:0]];
}
}
NSLog(@"%@", dataDictionary);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
[dataDictionary writeToFile:[documentsDir stringByAppendingPathComponent:@"WordDictionary.plist"] atomically:YES];
CSV FORMAT :
ability,ablty
able,abl
about,abt
above,abv
according,acc
account,acc
across,acrss
act,act
OUTPUT : plist Dictionary
NSString *fileObj = [NSString stringWithContentsOfFile:strBundle
encoding:NSUTF8StringEncoding
error:nil];
NSArray *objectArray = [fileObj componentsSeparatedByString:@"\n"];
NSLog(@"%@", objectArray);
NSMutableDictionary *dataDictionary = [[NSMutableDictionary alloc] init];
for (int i = 0; i < [objectArray count]; i++) {
NSArray *tempObj = [[objectArray objectAtIndex:i] componentsSeparatedByString:@","];
if (i != [objectArray count] - 1) {
[dataDictionary setValue:[tempObj objectAtIndex:1] forKey:[tempObj objectAtIndex:0]];
}
}
NSLog(@"%@", dataDictionary);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
[dataDictionary writeToFile:[documentsDir stringByAppendingPathComponent:@"WordDictionary.plist"] atomically:YES];
CSV FORMAT :
ability,ablty
able,abl
about,abt
above,abv
according,acc
account,acc
across,acrss
act,act
OUTPUT : plist Dictionary
No comments:
Post a Comment