Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

What could this error mean?

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

Here is my code:

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

I tried debuggin, and it dies once it enters the performRequestWithHandler. It goes the else block and dies with the error above.

like image 945
Richard Knop Avatar asked Apr 10 '12 19:04

Richard Knop


2 Answers

It means that you are passing an NSNumber where the called code expects an NSString or some other object that has a length method. You can tell Xcode to break on exceptions so that you see where exactly the length method gets called.

like image 89
zoul Avatar answered Nov 03 '22 08:11

zoul


Specifically this line of code:

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

the replyToID is not a String or has a method length. If you don't have this, or if you convert the replyToID to a String before setting it in params it should work.

like image 25
Sau Sheong Avatar answered Nov 03 '22 08:11

Sau Sheong