2012-04-10 15 views
20

Co ten błąd może oznaczać?[__NSCFNumber length]: nierozpoznany selektor wysłany do instancji 0x6d21350

[__NSCFNumber length]: unrecognized selector sent to instance 0x6d21350 

Oto mój kod:

NSString *urlString = @"http://api.twitter.com/1/statuses/update.json"; 
    NSURL *url = [NSURL URLWithString:urlString]; 

    NSMutableDictionary *params = [[NSMutableDictionary alloc] init]; 
    [params setObject:status forKey:@"status"]; 
    [params setObject:replyToID forKey:@"in_reply_to_status_id"]; 
    [params setObject:@"1" forKey:@"include_entities"]; 

    // Build the request with our parameter 
    TWRequest *request = [[TWRequest alloc] initWithURL:url parameters:params requestMethod:TWRequestMethodPOST]; 

    // Attach the account object to this request 
    [request setAccount:twitterAccount]; 

    [request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { 
     if (!responseData) { 
      // inspect the contents of error 
      NSLog(@"%@", [error localizedDescription]); 

      self.alert = [[UIAlertView alloc] initWithTitle:@"HTTP error" message:@"I could not connect to the Twitter API." delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil]; 
      [self.alert show]; 

      [self.replyDelegate replyRequestSuccessful:NO]; 
     } 
     else { 
      /*NSString *responseDataAsString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; 
      NSLog(responseDataAsString);*/ 

      NSError *error; 
      NSArray *replyResponse = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error]; 

      if (!replyResponse) { 
       NSLog(@"%@", [error localizedDescription]); 

       self.alert = [[UIAlertView alloc] initWithTitle:@"JSON error" message:@"I could not parse the JSON response from the Twitter API." delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil]; 
       [self.alert show]; 

       [self.replyDelegate replyRequestSuccessful:NO]; 
      } 
      else { 
       [self.replyDelegate replyRequestSuccessful:YES]; 
      } 
     } 
    }]; 

Próbowałem optymalnie spełniało i obumrze raz wejdzie on w performRequestWithHandler. To idzie na blok inny i umiera z powyższym błędem.

Odpowiedz

67

Oznacza to, że przechodzisz pod numer NSNumber, w którym kod wywoływany oczekuje od NSString lub innego obiektu z metodą length. Możesz powiedzieć Xcode, aby złamał wyjątki, aby zobaczyć, gdzie dokładnie wywoływana jest metoda length.

+7

Bardziej prawdopodobne, istnieje problem z jego zarządzaniem pamięcią i runtime/ramy oczekuje NSString, że tam nie ma już (przed przedwczesnym dealokacji) oraz NSNumber została przydzielona tam zamiast. Jeśli celowo spróbujesz wysłać 'length' do' NSNumber', kompilator może ostrzec cię. – dreamlax

+0

Nie, jeśli 'NSNumber' jest przekazywany w słowniku lub innym interfejsie, który usuwa typy. Ale masz rację, jest całkiem prawdopodobne, że coś nadmiernie uwalnia. Warto spróbować "NSZombieEnabled". – zoul

+0

Co masz na myśli przez "wymazuje typy"? – dreamlax

6

Konkretnie ta linia kodu:

[params setObject:replyToID forKey:@"in_reply_to_status_id"]; 

replyToID nie jest String lub ma metodę length. Jeśli nie masz tego, lub przekonwertujesz replyToID na ciąg przed ustawieniem go w params, powinno działać.

Powiązane problemy