这个错误可能意味着什么?
[__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];
}
}
}];
我尝试进行调试,但一旦进入performRequestWithHandler方法就停止了。它走到else代码块并出现上述错误。
NSNumber
是通过字典或其他擦除类型的接口传递的,则不会。但你说得对,他过度释放某些东西的可能性很大。尝试使用NSZombieEnabled
可能是个好主意。 - zoulid
而不是NSString
,那么很容易在期望NSString
的位置上放入NSNumber
而不被编译器注意到。通常,“类型擦除”是指从事物中剥离显式类型的过程。在某些语言的集合中,这是一个普遍存在的问题:当您将某些内容放入Objective-C集合(如NSArray
)中,然后再读取它时,编译器不再知道该事物的类型,因为它已经被擦除了。 - zoul