protocol nil vs throw philosophy

53 views
Skip to first unread message

Doug Warren

unread,
Mar 5, 2014, 1:38:04 PM3/5/14
to objection...@googlegroups.com
I'm curious what is the thoughts behind this throwing:

@interface SomeObject
@property(weak) id<NonImplementedProtocol> proto;
@end

@implementation
objection_requires_sel(@selector(proto));
@end

and this returning nil:
-(void) viewDidLoad {
   id<NonImplementedProtocol> proto = [[JSObjection defaultInjector] getObject:@protocol(NonImplementedProtocol)];
}

My plan is to use Injectors to cover object lifetime.  If it's not valid to construct an object (Status of a remote server being asked before the network connection has been established.)  injecting it would return nil.  I implemented this as a category on JSObjection and some of my unit tests noticed the difference between those two cases.  My general plan is to push down to the injector what it should do if a class isn't registered or a proto isn't registered where it could return nil, @throw (assert in our case.), or look for a fallback like we do with classes.
Reply all
Reply to author
Forward
0 new messages