#import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. //在程序中不要直接比較對象所屬的類,明智的作法是調用「類信息查詢方法」 //能夠正確處理那些使用了消息傳遞機制的對象 //oc中對象的本質:對象實例都是指向某塊內存數據的指針 NSDictionary *dic = [NSDictionary new]; dic = @{@"11":@"11"}; UIView *view = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)]; [self.view addSubview:view]; NSLog(@"%d",[dic isMemberOfClass:[NSDictionary class]]);//判斷出對象是否爲某個特定類的實例 0 ??????爲何是否? NSLog(@"%d",[dic isMemberOfClass:[NSMutableDictionary class]]);//0 NSLog(@"%d",[dic isKindOfClass:[NSDictionary class]]);//判斷出對象是否爲某類或其派生類的實例 1 NSLog(@"%d",[dic isKindOfClass:[NSMutableDictionary class]]);//0 NSLog(@"%d",[dic isKindOfClass:[NSArray class]]);// 0 NSLog(@"%d",[view isMemberOfClass:[UIView class]]);//1 } -(NSString *)commaSeparatedStringFromOnjects:(NSArray *)array { NSMutableString *string =[NSMutableString new]; for (id object in array) { if ([object isKindOfClass:[NSString class]]) { [string appendFormat:@"%@,",object]; } else if ([object isKindOfClass:[NSNumber class]]) { [string appendFormat:@"%d,",[object intValue]]; } else if ([object isKindOfClass:[NSData class]]) { // NSString *base64Encode = /**/ // [string appendFormat:@"%@,",base64Encode]; } else { //type not } } return string; }