ARC가있는 프로젝트와없는 프로젝트의 차이점을 연구 중입니다. 프로토콜을 구현해야하는 사용자 정의 라이브러리를 사용합니다. ARC가없는 프로젝트에서 콜백 (onEvent)이 호출되었지만 ARC 프로젝트에서는 발생하지 않습니다. 가() 콜백의 onEvent를 불렀다 - - 내가 프로토콜 코드에 액세스 할 필요가 없습니다ARC가 작동하지 않는 프로토콜
을하지만 난 다음 구현 틀렸다 생각 :
의 ViewController :
@implementation ViewController
- (IBAction)pressed:(id)sender {
ObjectA *sd = [[ObjectA alloc] init];
[sd startWith:@"myString"];
}
인터페이스 ObjectA :
@interface ObjectA : NSObject <MyProtocol>
@property (nonatomic, strong) id<MyProtocol> myProtocol;
- (void) startWith:(NSString *)myString;
@end
구현 ObjectA :
- (void) startWith:(NSString *)myString
{
id<MyProtocol> protocolDelegate = self;
self.myProtocol = [[ObjectB alloc] init: protocolDelegate];
[self.myProtocol doStuff];
}
- (void) onEvent
{
NSLog(@"Called");
}
인터페이스 ObjectB :
@interface ObjectB : NSObject<MyProtocol>
질문
은 다음과 같습니다 왜 ARC 프로젝트 "의 onEvent은"호출되지 않습니다?의견을 보내 주셔서 감사합니다.
편집 :이 방법으로의 ViewController을 변경 해결 한
:
귀하의 설명과 솔루션을 기반으로@interface ViewController()
@property (nonatomic, strong) ObjectA *sd;
@end
@implementation ViewController
- (void)viewDidLoad {
_sd = [[ObjectA alloc] init];
}
- (IBAction)pressed:(id)sender {
[sd startWith:@"myString"];
}
'onEvent'에 대한 호출이 표시되지 않습니다. – shallowThought
내가 말했듯이, 나는 프로토콜을 코딩 할 수있는 권한이 없다. 이 프로토콜은 라이브러리에서 사용되기 때문입니다. –
이해하십시오. '@property (nonatomic, strong) TypeOfClassFromLibrary myLibClassInstance; '속성을 만들어야합니다. 그런 다음'viewDidLoad' :'self.myLibClassInstance = [[TypeOfClassFromLibrary alloc] init]; self.myLibClassInstance.nameOfProtocol = self;' – shallowThought