Iphone CHCSVParser-如何从Web服务器加载

Iphone CHCSVParser-如何从Web服务器加载,iphone,ios,ipad,csv,ios6,Iphone,Ios,Ipad,Csv,Ios6,我想从每天更新的Web服务器解析csv。我正在使用此链接中的csvparser,我正在使用以下代码: NSError *err = [[[NSError alloc] init] autorelease]; NSString *lunchFileURL = [[NSString stringWithFormat:@"http://www.somewhere.com/LunchSpecials.csv"] stringByAddingPercentEscapesUsingEncoding:NSU

我想从每天更新的Web服务器解析csv。我正在使用此链接中的csvparser,我正在使用以下代码:

 NSError *err = [[[NSError alloc] init] autorelease];
NSString *lunchFileURL = [[NSString stringWithFormat:@"http://www.somewhere.com/LunchSpecials.csv"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *lunchFile = [NSString stringWithContentsOfURL:[NSURL URLWithString:lunchFileURL] encoding:NSUTF8StringEncoding error:&err];
CHCSVParser *p = [[CHCSVParser alloc] initWithContentsOfCSVString:lunchFile usedEncoding:&encoding error:nil];        
我得到这个错误:

 No visible @interface for 'CHCSVParser' declares the selector 'initWithContentsOfCSVString:usedEncoding:error:'        
我检查了此链接,但它不起作用。我是ios的noob,请告诉我如何修复此问题。非常感谢您的帮助。提前感谢。

可能是:

NSError *err;
NSString *lunchFileURL = [[NSString stringWithFormat:@"http://www.somewhere.com/LunchSpecials.csv"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSString *lunchFile = [NSString stringWithContentsOfURL:[NSURL URLWithString:lunchFileURL]
                                               encoding:NSUTF8StringEncoding
                                                  error:&err];

// if you're going to create a CHCSVParser yourself, the syntax is:

CHCSVParser *p = [[CHCSVParser alloc] initWithCSVString:lunchFile
                                               encoding:NSUTF8StringEncoding
                                                  error:&err];

// or, if you're going to use NSArray+CHCSVAdditions.h, the syntax might be:

NSArray *array = [[NSArray alloc] initWithContentsOfCSVString:lunchFile
                                                     encoding:NSUTF8StringEncoding
                                                        error:&err];
注:

  • 你不需要
    alloc
    /
    init
    这个
    NSError
    对象;这些接受
    NSError**
    参数的类将在遇到错误时为您创建自动释放错误对象;否则他们就别管它了

  • CHCSVParser
    类方法不是
    initwithcontentsofsofcsvstring
    ,而是
    initWithCSVString

  • 或者,如果使用
    NSArray
    类扩展,则语法为
    arrayWithContentsOfCSVString
    initWithContentsOfCSVString
    ;及

  • 您指定了
    &encoding
    的编码,但此参数不是指针,因此我不认为这可能是正确的;我刚刚指定了编码


我假设您想使用
NSArray+CHCSVAdditions
类别方法
initwithcontentsofsofcsvstring
arraywhithcontentsofsofcsvstring
(它为您提供了一个
autorelease
对象),而不是
CHCSVParser
,但这取决于您。

感谢Sachin的编辑。仅供参考,我用两个例子更新了我的答案。总之,
initWithContentsOfCSVString
是一个
NSArray
分类方法,而不是
CHCSVParser
方法。这是有史以来最好的答案。非常感谢Rob。太棒了!!