내 웹 API에 액세스하는 일반 저장소 (패턴)를 만들려고합니다. 프로토콜이 객관적으로 작동하는 방법을 이해하는 데 어려움을 겪고 있습니다. -c (인터페이스가 약간 다른 C#에서 왔습니다).다른 프로토콜의 매개 변수로 Objective-C 프로토콜
내가하려고하는 것은 ProtocolA가 다른 ProtocolB의 매개 변수가되고 ProtocolB의 ProtocolB 액세스 메소드 구현에서 ProtocolB로 전달 된 객체가 ProtocolA 자체를 구현해야하기 때문입니다. 나는 그것에 대해 정확하게 생각하고 있는가?
이
내가 지금까지 가지고 있지만 그것을 얻이 수없는 것 무엇인가 - 어쩌면 나의 논리는 잘못된 것입니다 ://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] <-- this doesn't work...
}
@end
C#에서 오는 경우에도 Obj-C에서 C# 명명 규칙을 사용하지 마십시오. 예를 들어 모든 메소드 이름은 소문자로 시작해야하며 매개 변수를 설명해야합니다 (예 : 'getForEntity :' – Sulthan
@ Suulthan 고맙다, 고마워! – crizzwald