-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppController.m
59 lines (42 loc) · 1.43 KB
/
AppController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// MainWindowController.m
// Plist Converter
//
// Created by Danilo Campos on 3/30/09.
// Copyright 2009 Danilo Campos. All rights reserved.
//
#import "AppController.h"
#import "parseCSV.h"
@implementation AppController
@synthesize pathAsString;
- (IBAction)executeConversion:(id)sender {
// NSLog(@"Converting %@",pathAsString);
CSVParser *parser = [CSVParser new];
[parser openFileWithPath:pathAsString];
NSMutableArray *csvContent = [parser parseFile];
[parser closeFile];
if (pathAsString != nil) {
NSArray *keyArray = [csvContent objectAtIndex:0];
NSMutableArray *plistOutputArray = [NSMutableArray array];
NSInteger i = 0;
for (NSArray *array in csvContent) {
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
NSInteger keyNumber = 0;
for (NSString *string in array) {
[dictionary setObject:string forKey:[keyArray objectAtIndex:keyNumber]];
keyNumber++;
}
if (i > 0) {
[plistOutputArray addObject:dictionary];
}
i++;
}
// NSLog(@"Plist output array %@", plistOutputArray);
NSMutableString *mutableString = [NSMutableString stringWithString:pathAsString];
[mutableString replaceOccurrencesOfString:@".csv" withString:@".plist" options:0 range:NSMakeRange([mutableString length]-4, 4)];
NSURL *url = [NSURL fileURLWithPath:mutableString];
// NSLog(@"Write to URL %@",url);
[plistOutputArray writeToURL:url atomically:YES];
}
}
@end