2012-04-02 4 views
1

가 어떻게 ARC이 코드 리팩토링 것 ARC 준수를위한이 코드 :리팩토링

- (UIGestureRecognizer *)newTapRecognizerWithSelector:(SEL)selector 
{ 
    return [[UITapGestureRecognizer alloc] initWithTarget:self action:selector]; 
} 
+3

ARC는 모든 참조 문제를 제어합니다. 그래서 당신은 autorelease 메시지를 제거 할 수 있습니다 (또한 유지, 해제, dealloc). 또는 나는 당신의 의도를 오해하고 있습니까? – TRD

답변

4

방법을 오토 릴리즈 문을 제거하고 이름 변경에 대한

- (UIGestureRecognizer *)createTapRecognizerWithSelector:(SEL)selector { 
    return [[[UITapGestureRecognizer alloc] initWithTarget:self action:selector] autorelease]; 
} 

감사 autorelease. 그럴 수 있습니다

희망이 도움이됩니다.

+0

왜 내가 오류 메시지 "왜 선언되지 않은 선언 된 식별자 'UITapRecognizer'의 사용을 얻는 지 아무 아이디어 나? 다시 감사합니다 – hanumanDev

+1

* new *로 시작하는 이름을 변경하면 [return unretained] (http : //clang.llvm)의 메소드가 암시 적으로 변경됩니다. .org/docs/AutomaticReferenceCounting.html # objects.operands.other-returns)를 [반환 됨] (http://clang.llvm.org/docs/AutomaticReferenceCounting.html#objects.operands.retained-returns)으로 반환하십시오. 괜찮아요, 원래 방법과 다릅니다 – Caleb

+0

@Caleb, Indeed - 주목할 점은 'create'가 자동 렌더링 된 객체를 반환했지만 ARC에 대해 리팩토링 된 'new'메서드는 호출자에 대한 소유 된 참조를 반환하고, 내 생각에, 이것은 코드의 행동을보다 정확하게 표현합니다. 'create'를 계속 사용하려면 자동 렌더링 된 객체가 ARC에서 더 이상 반환되지 않을 때 반환된다는 것을 계속 암시하는 것입니다. 폭발물 사건을 털어 놓으 라. – isaac