NSScanner在scanUpToString上无法识别的选择器

时间:2012-12-04 08:28:59

标签: objective-c ios xcode ios6 nsscanner

我使用Dimitris的URL parser class但是当init对象转换initWithURLString时遇到问题:

- (id) initWithURLString:(NSString *)url{
    self = [super init];
    if (self != nil) {
        NSString *string = url;
        NSScanner *scanner = [NSScanner scannerWithString:string];
        [scanner setCharactersToBeSkipped:[NSCharacterSet characterSetWithCharactersInString:@"&?"]];
        NSString *tempString;
        NSMutableArray *vars = [NSMutableArray new];
        //ignore the beginning of the string and skip to the vars
        [scanner scanUpToString:@"?" intoString:nil];
        while ([scanner scanUpToString:@"&" intoString:&tempString]) {
            [vars addObject:[tempString copy]];
        }
        self.variables = vars;
    }
    return self;
}

在线[scanner scanUpToString:@"?" intoString:nil];我收到错误:

  

[NSURL长度]:无法识别的选择器发送到实例0x1f8c2050

怎么可能?

编辑:也许您想知道我如何调用URLParser:

URLParser *urlParser = [[URLParser alloc]initWithURLString:[info valueForKey:UIImagePickerControllerReferenceURL]];

UIImagePickerControllerReferenceURL值是:assets-library://asset/asset.PNG?id = 8D2F0449-11A3-4962-9D60-C446831645D7& ext = PNG

1 个答案:

答案 0 :(得分:1)

您将NSURL传递给initWithURLString,但您应该将它与NSString一起使用,如下所示:

NSString* urlString = [NSString stringWithFormat:@"%@",[info valueForKey:UIImagePickerControllerReferenceURL]];
URLParser *parser = [[[URLParser alloc] initWithURLString:urlString] autorelease];