2012-04-10 15 views
20

¿Qué podría significar este error?[__NSCFNumber length]: selector no reconocido enviado a la instancia 0x6d21350

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

Aquí está mi código:

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]; 
      } 
     } 
    }]; 

Probé debuggin, y se muere una vez que entra en el performRequestWithHandler. Va el bloque else y muere con el error anterior.

Respuesta

67

Significa que está pasando un NSNumber donde el código llamado espera un NSString o algún otro objeto que tenga un método length. Puedes decirle a Xcode que rompa las excepciones para que veas exactamente dónde se llama el método length.

+7

Es más probable que exista un problema con la administración de su memoria, y el entorno de ejecución/framework espera un NSString que ya no existe (de la desasignación prematura), y en su lugar se ha asignado un NSNumber. Si intencionalmente intentas enviar 'length' a un' NSNumber', el compilador podría advertirte. – dreamlax

+0

No si el 'NSNumber' se pasa en un diccionario o a través de alguna otra interfaz que borre los tipos. Pero tienes razón, es bastante probable que esté liberando demasiado algo. Puede ser una buena idea intentar con 'NSZombieEnabled'. – zoul

+0

¿Qué quiere decir con "borra los tipos"? – dreamlax

6

Específicamente esta línea de código:

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

la replyToID no es una cadena o tiene un método length. Si no tiene esto, o si convierte el replyToID en una Cadena antes de configurarlo en params, debería funcionar.

Cuestiones relacionadas