当我试图运行isKindofClass时,我得到一个sigabort

时间:2011-09-19 10:33:54

标签: cocoa

void PrintIntrospectionInfo()
{
// NSLog(@"Comes here1");

NSArray *myArray;
NSDate *aDate = [NSDate distantFuture];
NSValue *aValue = [NSNumber numberWithInt:5];
NSURL *urlObj = [NSURL URLWithString:@"http://www.yahoo.com"];
NSString *aString = @"string";
NSMutableString *mString = [NSMutableString stringWithFormat: @"Hello, %@", aString];
NSDictionary *stanford = [NSDictionary dictionaryWithObjectsAndKeys:@"http://www.stanford.edu", @"Stanford University", @"http://www.apple.com",@"Apple", @"http://cs193p.stanford.edu", @"CS193P",@"http://itunes.stanford.edu",@"Stanford on iTunesU",@"http://stanfordshop.com",@"Stanford Mall", nil];

myArray = [NSArray arrayWithObjects:aDate, aValue, aString,stanford,urlObj,mString, nil];

for(id someObject in myArray)
{
    NSLog(@"Comes here");

    if([someObject isKindofClass:[NSString string]])
    {

    }
}


}

1 个答案:

答案 0 :(得分:2)

待办事项

for(id someObject in myArray)
{
    NSLog(@"Comes here");
    if([someObject isKindOfClass:[NSString class]])
    {

    }
}

代替。请注意Of的{​​{1}}是大写的。我建议您使用isKindOfClass代替NSObject*。然后编译器警告您方法id不可用。通常,除非您使用的内容不是isKindofClass,否则您无需使用id

NSObject