如何为所有push segues制作符号断点?

时间:2016-01-04 15:02:33

标签: ios objective-c xcode debugging segue

我正在调试我的应用程序,并且遇到了一个正在执行segue的问题,但我不能在我的生活中找出它的调用位置。

我想知道是否可以添加一个断点,以便app暂停并显示从哪里调用它?

我尝试添加符号断点,但无法使其正常工作。

1 个答案:

答案 0 :(得分:1)

为UIViewController创建类别并将其添加到其中:

+ (void)load {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        Class class = [self class];

        SEL originalSelector = @selector(prepareForSegue:sender:);
        SEL swizzledSelector = @selector(yd_prepareForSegue:sender:);

        Method originalMethod = class_getInstanceMethod(class, originalSelector);
        Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);

        BOOL didAddMethod = class_addMethod(class, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod));

        if (didAddMethod) {
            class_replaceMethod(class, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));
        } else {
            method_exchangeImplementations(originalMethod, swizzledMethod);
        }
    });
}

- (void)yd_prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    [self yd_prepareForSegue:segue sender:sender];
    NSLog(@"prepareForSegue From: %@", self);
}