思路:将所有NSFoundation中的类型记录到一个数组中,然后通过数组的
containsObject:方法去判断所要判断的类型是否包含在此数组中.
简单代码如下:
+ (BOOL)isClassFromFoundation:(Class)c {
NSArray* foundationClasses = @[@"NSObject", @"NSNumber",@"NSArray",@"NSMutableArray",@"NSData",@"NSMutableData",@"NSDate",@"NSDictionary",@"NSMutableDictionary",@"NSString",@"NSMutableString"];
//判断c是否在foundationClasses数组中
return [foundationClasses containsObject:c];
}
时间: 2024-10-19 22:52:14