2012-04-10 11 views
20

के लिए भेजा इस त्रुटि क्या मतलब हो सकता है?[__NSCFNumber लंबाई]: गैर मान्यता प्राप्त चयनकर्ता उदाहरण 0x6d21350

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

यहाँ मेरी कोड है:

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

मैं debuggin की कोशिश की, और यह मर जाता है एक बार यह performRequestWithHandler प्रवेश करती है। यह अन्य ब्लॉक चला जाता है और ऊपर की त्रुटि के साथ मर जाता है।

उत्तर

67

इसका मतलब है कि आप NSNumber पास कर रहे हैं जहां कॉल किया गया कोड NSString या किसी अन्य ऑब्जेक्ट की अपेक्षा करता है जिसमें length विधि है। आप अपवादों पर तोड़ने के लिए इतना है कि आप देख जहां बिल्कुल length विधि कहा जाता हो जाता है Xcode बता सकते हैं।

+7

अधिक संभावना है, वहाँ उनकी स्मृति प्रबंधन के साथ एक मुद्दा है, और रनटाइम/ढांचा एक NSString कि (समय से पहले आवंटन रद्द करने से) अब वहां नहीं है उम्मीद कर रही है, और एक NSNumber वहाँ के बजाय आबंटित की गई है। यदि आप उद्देश्य से 'NSNumber' को 'लंबाई' भेजने का प्रयास करते हैं, तो संकलक आपको आशा करता है कि आपको चेतावनी दी जाएगी। – dreamlax

+0

'NSNumber' एक शब्दकोश में या किसी अन्य इंटरफ़ेस प्रकार मिटा देता है के माध्यम से पारित कर दिया है, तो ऐसा नहीं है। लेकिन आप सही हैं, यह काफी संभावना है कि वह कुछ खत्म कर रहा है। 'NSZombieEnabled' के साथ प्रयास करना एक अच्छा विचार हो सकता है। – zoul

+0

आप "प्रकार मिटा देता है" से क्या मतलब है? – dreamlax

6

विशेष रूप से कोड की इस पंक्ति:

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

replyToID एक स्ट्रिंग नहीं है या एक विधि length है। आप इस की जरूरत नहीं है, अथवा यह काम करना चाहिए अगर आप पैरामीटर में सेट करने से पहले एक स्ट्रिंग के लिए replyToID परिवर्तित।

संबंधित मुद्दे