Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typo in block replacement of [UIView initWithFrame]? #19

Closed
respan opened this issue Jul 18, 2018 · 3 comments
Closed

Typo in block replacement of [UIView initWithFrame]? #19

respan opened this issue Jul 18, 2018 · 3 comments
Assignees

Comments

@respan
Copy link

respan commented Jul 18, 2018

// UIView+DBUserInterfaceToolkit.h

+ (void)load {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        __block IMP originalInitWithCoderIMP = [self replaceMethodWithSelector:@selector(initWithCoder:)
                                                                         block:^UIView * (UIView *blockSelf, NSCoder *aDecoder) {
                                                                            UIView *res = ((UIView * (*)(id, SEL, NSCoder *))originalInitWithCoderIMP)(blockSelf, @selector(initWithCoder:), aDecoder);
                                                                            [res db_refreshDebugBorders];
                                                                            [res db_registerForNotifications];
                                                                            return res;
                                                                         }];
        __block IMP originalInitWithFrameIMP = [self replaceMethodWithSelector:@selector(initWithFrame:)
                                                                         block:^UIView * (UIView *blockSelf, CGRect frame) {
                                                                             UIView *res = ((UIView * (*)(id, SEL, CGRect))originalInitWithFrameIMP)(blockSelf, @selector(initWithCoder:), frame);
                                                                             [res db_refreshDebugBorders];
                                                                             [res db_registerForNotifications];
                                                                             return res;
                                                                         }];
        __block IMP originalDeallocIMP = [self replaceMethodWithSelector:NSSelectorFromString(@"dealloc")
                                                                   block:^(__unsafe_unretained UIView *blockSelf) {
                                                                       [[NSNotificationCenter defaultCenter] removeObserver:blockSelf];
                                                                       ((void (*)(id, SEL))originalDeallocIMP)(blockSelf, NSSelectorFromString(@"dealloc"));
                                                                   }];
    });
}

Is there a bug with this line:

UIView *res = ((UIView * (*)(id, SEL, CGRect))originalInitWithFrameIMP)(blockSelf, @selector(initWithCoder:), frame);

You pass @selector(initWithCoder:) but shouldn't you pass @selector(initWithFrame:)?

@respan respan changed the title -[UIView initWithFrame:] must be used from main thread only Typo in block replacement of [UIView initWithFrame]? Jul 18, 2018
@dbukowski
Copy link
Owner

Hello @respan, thanks for reporting that, good catch! That's what happens when you copy and paste in a non-type-safe environment 😅 Will be fixed in the next release!

@dbukowski dbukowski self-assigned this Jul 19, 2018
@respan
Copy link
Author

respan commented Jul 20, 2018

Thanks!

@dbukowski
Copy link
Owner

Finally fixed in 0.5.1. Thanks again for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants