开发者

I get a sigabort when it tries to run isKindofClass

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 stringWit开发者_如何学编程hFormat: @"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]])
    {

    }
}


}


Do

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

    }
}

instead. Note that Of of isKindOfClass is in the upper case. I recommend you to use NSObject* instead of id. Then the compiler warns you that the method isKindofClass is not available. Usually, you don't need to use id unless you use something which is not an NSObject :

for(NSObject* someObject in myArray)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜