문제

  StringReply = [[NSString alloc] initWithData:dataReply encoding:NSUTF8StringEncoding];

         //Regex Out Artist Name
         //NSString *regEx = ; 
         NSArray *iTunesAristName = [stringReply componentsMatchedByRegex: @"(?<=artistname\":\")([^<]+)(?=\")"]; 

         if ([iTunesAristName isEqual:@""]) { 
           NSLog(@"Something has messed up");
           //Regex Out Song Name
          }else{
           NSLog(iTunesAristName);
          }

         NSLog(iTunesAristName);
         [stringReply release];

I just keep getting this error ?

        2010-09-29 21:15:16.406 [2073:207] *** -[NSCFArray length]: unrecognized selector sent to instance 0x4b0b800
        2010-09-29 21:15:16.406 [2073:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFArray length]: unrecognized selector sent to instance 0x4b0b800'
        2010-09-29 21:15:16.407 [2073:207] Stack: (

please help its driving me crazy

도움이 되었습니까?

해결책

The first argument to NSLog is supposed to be a format string. You're passing an NSArray. When the function tries to treat your array as a string, you get that error. Instead, use NSLog(@"%@", iTunesAristName);.

다른 팁

Chuck has answered your question, but I've noticed something else that is problematic.

NSArray is an array, not a string, so [iTunesArtistName isEqual:@""] will never return true, because they are different classes. Even if iTunesArtistName was a string, it should be compared using the isEqualToString: method, not isEqual:.

If you want to extract only the artist's name, you might be able to do this:

NSArray *matches = [stringReply componentsMatchedByRegex: @"(?<=artistname\":\")([^<]+)(?=\")"]; 

if ([matches count] == 0)
{
    NSLog(@"Could not extract the artist name");
}
else
{
    NSString *iTunesArtistName = [matches objectAtIndex:0];

    NSLog(@"Artist name: %@", iTunesArtistName);
}

I see you're using RegexKitLite, make sure you import libicucore.dylib, i was getting the same error until i imported that library.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top