Ios 如何检查UIViewController类是定义为SDK的一部分还是用户定义的?
是否有方法检查给定的UIViewController是用户定义的还是系统提供的Ios 如何检查UIViewController类是定义为SDK的一部分还是用户定义的?,ios,objective-c,Ios,Objective C,是否有方法检查给定的UIViewController是用户定义的还是系统提供的 //The following may be implemented in one of the View Controller lifecycle methods by swizzling NSString *controllerName = NSStringFromClass([self class]); if([Helper controllerIsUserDefined:controllerName]) {
//The following may be implemented in one of the View Controller lifecycle methods by swizzling
NSString *controllerName = NSStringFromClass([self class]);
if([Helper controllerIsUserDefined:controllerName]) {
//Let us do this only for user-defined UIViewController classes
}
我正在寻找一种实现
controllerIsUserDefined
方法的方法。此外,我不喜欢在用户定义的ViewController类中添加虚拟属性或方法,然后使用respondsToSelector
进行检查,因为此功能也可能在现有项目中使用 您可以检查主捆绑包中是否定义了类,这可能会解决您的问题
if ([[NSBundle mainBundle] isEqual:[NSBundle bundleForClass:[self class]]]) {
// Object class defined in the main bundle
}
如果类是在用户提供的框架中定义的,这可能不起作用。非常好,非常感谢。这对我来说很好,我不希望任何用户提供的框架在我的用例中扮演角色。