Skip to content

Skip undefined protocol silently.#19

Merged
AlexDenisov merged 2 commits intorailsware:masterfrom
kkazuo:undefined-protocol
May 30, 2014
Merged

Skip undefined protocol silently.#19
AlexDenisov merged 2 commits intorailsware:masterfrom
kkazuo:undefined-protocol

Conversation

@kkazuo
Copy link
Contributor

@kkazuo kkazuo commented Apr 3, 2014

This can happen when you defines the protocol but does not exist class that implement it.

This can happen when you defines the protocol but does not exist class that implement it.
@kkazuo
Copy link
Contributor Author

kkazuo commented Apr 3, 2014

I have multiple app targets.
One target contains a class that implement the protocol, another targets does not.
So I can build two little different apps.
Is this wrong idea?

@AlexDenisov
Copy link
Contributor

@kkazuo, could you tell us how do you use this protocol?
Unknown protocol is an edge case, so BM should stop executing to notify user that something went wrong, on the other hand it's not critical, so we can just skip this step with some extra logging...

@0xc010d, what do you think?

@kkazuo
Copy link
Contributor Author

kkazuo commented Apr 3, 2014

The build target A and B has linking this class:

@interface X : NSObject
@property (weak, nonatomic) id<MyProtocol> myDelegate;
@end

@implementation X
- (void)doSomething
{
  id delegate = self.myDelegate;
  if ([delegate respondsToProtocol:@protocol(MyProtocol)]) {
    [delegate anProtocolMethod];
  }
}
@end

Only target A has linking a class that implements MyProtocol.
So target B's myDelegate is always nil. An nil delegate is no problem.

I can escape crashing BloodMagic with dummy class that implements MyProtocol.

@interface DoesNotUseAnywhereClass : NSObject <MyProtocol>
@end
@implementation
- (void)anProtocolMethod
{
  // blank, because does not instanciate this class anywhere.
}
@end

Is this a preferred workaround?

@0xc010d
Copy link
Contributor

0xc010d commented Apr 3, 2014

Dummy class doesn't sound as a proper workaround, of course. I'll investigate it tomorrow.
Do you #import the header with that protocol definition?

Seems like we've already had similar issue, please check if it's not the same in your case: #9 (comment)

@0xc010d
Copy link
Contributor

0xc010d commented Apr 4, 2014

@kkazuo I think that might've been the issue. But, just to close that topic, could you please modify your pull request so it would be like that:

        if (!protocol) {
            NSLog(@"BloodMagic: Protocol %s hasn't been found. Please check if you include the header with that protocol description in your .m file", protocolName.c_str());
            continue;
        }

@AlexDenisov
Copy link
Contributor

Totally agree with @0xc010d.

@kkazuo
Copy link
Contributor Author

kkazuo commented Apr 4, 2014

@0xc010d
Copy link
Contributor

0xc010d commented Apr 4, 2014

Ok.. We might need to do a further investigation of that.

@kkazuo thank you for the finding!

@kkazuo
Copy link
Contributor Author

kkazuo commented Apr 4, 2014

Thank you for the discussion!

@AlexDenisov AlexDenisov merged commit b0d5bbb into railsware:master May 30, 2014
@AlexDenisov
Copy link
Contributor

@kkazuo, finally I've merged this one. Thank you!

@kkazuo kkazuo deleted the undefined-protocol branch May 30, 2014 09:23
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

Successfully merging this pull request may close these issues.

3 participants