views:

17

answers:

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

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

         if ([iTunesAristName isEqual:@""]) { 
           NSLog(@"Something has fucked 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

A: 

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
Im watching Chuck atm hehe, anyway i cannot retrieve items from the array whatsoever.
im getting nothing in the array and i am 2000% sure the regex is correct
@user393273: Since you're crashing the app, I imagine retrieving items from the array would be impossible. If you still can't retrieve items when the app is working correctly, that's another problem.
Chuck
A: 

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);
}
dreamlax