大家好!
如何判断一个类是系统还是自定义?
Custom的类也继承自NSObject。
如何区分?
请,THX〜
补充,像这样:
- (void)aaaa:(Class)aCustomClass
{
id instance = [[aCustomClass alloc] init];
NSArray * array = GET_A_CLASS_ALL_PROPERTY(aCustomClass); //it is a NSString array.
for (NSString * property in array)
{
Class classOfTheProperty = GET_THE_PROPERTY_CLASS(property); //the property's Class.
if ([classOfTheProperty isKindOfClass:NSString.class])
{
[instance setObject:@"1234" forKey:property];
}
else if (IS_CUSTOM_CLASS) //CUSTOM_CLASS maybe has less one hundred.
{
//Continue inner.
[self aaaa:classOfTheProperty];
}
else if (IS_SYSTEM_CLASS) //SYSTEM_CLASS definite has more than hundreds.
{
//Do Nothing.
}
}
}
答案 0 :(得分:2)
您可以检查该类是否是从应用程序的主程序包加载而不是从框架加载的:
Class c = ...
NSBundle *b = [NSBundle bundleForClass:c];
if (b == [NSBundle mainBundle]) {
// Custom class ...
}
答案 1 :(得分:0)
您可以通过创建它的obj来检查类,并使用方法 isKindOfClass
进行检查if ([element isKindOfClass:[customClassName class]]) //check wether object is of custom class
{
// Custom Class
}
else if ([element isKindOfClass:[systemClassName class]])
// System Class
}