Warning while adding and using a new method in external library protocol

后端 未结 3 1447
迷失自我
迷失自我 2021-01-15 09:32

I am using a external library and one of my view controller is registering as delegate for a class in that framework. Now, at one place I want to execute some code on this d

相关标签:
3条回答
  • 2021-01-15 09:33
    • (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { if ([self.libraryController.delegate respondsToSelector:@selector(actionTaken)]) { [self.libraryController.delegate performSelector:@selector(actionTaken)]; }

    Using performSelector instead of directly calling a method will remove warning for sure.

    0 讨论(0)
  • 2021-01-15 09:38

    Write a new protocol that extends the old one, and conform to that, something like:

    @protocol MyNewProtocol <OtherProtocol>
       - (void) myCoolMethod;
    @end
    
    0 讨论(0)
  • 2021-01-15 09:41

    The property libraryController.delegate is defined in the external library to conform to LibraryDelegate. Try to downcast to MyExtendedDelegate before you call the method from your extended protocol.

    if ([self.libraryController.delegate conformsToProtocol:@protocol(MyExtendedDelegate)])
    {
        id<MyExtendedDelegate> extendedDelegate = (id<MyExtendedDelegate>)self.libraryController.delegate;
        if ([extendedDelegate respondsToSelector:@selector(actionTaken)])
        {
            [extendedDelegate actionTaken];
        }
    }
    
    0 讨论(0)
提交回复
热议问题