CHCSV Parser错误:没有已知的选择器类的方法'arrayWithContentsOfCSVFile:encoding:error:'

时间:2013-08-17 20:36:03

标签: ios objective-c

尝试使用CHCSV解析器时:

#import "CHCSVParser.h"
....

- (IBAction)hi:(id)sender {
    NSString *path = [[NSBundle mainBundle] pathForResource:@"nood" ofType:@"csv"];

    NSError *error = nil;
    NSArray *rows = [NSArray arrayWithContentsOfCSVFile:path encoding:NSUTF8StringEncoding error:&error];
    if (rows == nil) {
        //something went wrong; log the error and exit
        NSLog(@"error parsing file: %@", error);
        return;
    }

}

我收到错误:

  

没有已知的选择器arrayWithContentsOfCSVFile的类方法:encoding:error:

我已经包含了CHCSV标头,但仍然会发生此错误。 这个问题与this问题完全相同,但从未得到回答,所以请不要将其标记为副本。

2 个答案:

答案 0 :(得分:2)

The header from github似乎没有这样的方法。您的选择似乎是:

+ (instancetype)arrayWithContentsOfCSVFile:(NSString *)csvFilePath;
+ (instancetype)arrayWithContentsOfCSVFile:(NSString *)csvFilePath options:(CHCSVParserOptions)options;

请注意,两者都没有encoding:参数。

答案 1 :(得分:0)

由于这个问题很久以前被问到,但我仍然会添加

这些方法已弃用,Dev已在.h文件中重写。

相反,你必须使用

- (IBAction)hi:(id)sender {
NSString *path = [[NSBundle mainBundle] pathForResource:@"nood" ofType:@"csv"];


NSArray *rows = [NSArray arrayWithContentsOfCSVURL:[NSURL fileURLWithPath:path] options:options];
if (rows == nil) {
    //something went wrong; log the error and exit
    NSLog(@"error parsing file: %@", error);
    return;
}

}