Objective-C protocol as parameter in another protocol -
i trying create generic repository (pattern) accesses web api. having trouble understanding how protocols work in objective-c (i come c# interfaces bit different).
what trying have protocola parameter in protocolb , in implementation of protocolb access methods on protocola, since object passed in protocolb must implement protocola itself. thinking correctly?
this have far, can't seem work - maybe logic wrong:
//pgenericmodel.h @protocol pgenericmodel <nsobject> - (void)testmethod; @end
//pgenericrepository.h #import "pgenericmodel.h" @protocol pgenericrepository <nsobject> @required - (void)get:(id<pgenericmodel>*)entity; @end
//genericrepository.m #import "genericrepository.h" @implementation genericrepository - (void)get:(id<pgenericmodel>*)entity { //get [entity testmethod] <-- doesn't work... } @end
it not working because id
type pointer objective-c object.
so should declare signature as
- (void)get:(id<pgenericmodel>)entity
not id<pgenericmodel>*
, otherwise argument pointer pointer objective-c object, can't send messages unless concrete value.
Comments
Post a Comment