2011-06-11 3 views
4
를 @synthesize

가능한 중복 :
Prefixing property names with an underscore in Objective C의 Obj-C는

여기

아이폰 앱 개발자 초급 :하는 .m

에서 .H

@property (nonatomic, retain) IBOutlet UILabel *detailDescriptionLabel; 

에서

@synthesize detailDescriptionLabel = _detailDescriptionLabel; 

나는 이것이 무엇을하고, 저를 던지고있다

@synthesize detailDescriptionLabel; 

= _을보고 사용 해요?

+0

또한 [어떻게 Cocoa Objective-C 클래스의 변수 앞에 밑줄을 표시합니까?] (http://stackoverflow.com/questions/822487/how-does-an-underscore-in-front-of) -a-variable-in-a-cocoa-objective-c-class-work) 및 [속성 이름의 밑줄 접두사] (http://stackoverflow.com/questions/5582448/underscore-prefix-on-property-name) –

+0

iOS 5는 NDA에 속해 있습니다. 저것을 위반하지 않기 위하여 편집 해. – bbum

답변

6

각 속성에는 인스턴스 변수가 있습니다. 언어를 사용하면 이름을 다르게 지정할 수 있습니다. @synthesize detailDescriptionLabel = _detailDescriptionLabel;을 수행하면 기본적으로 detailDescriptionLabel 속성의 백업 인스턴스 변수로 _detailDescriptionLabel을 사용한다고 말합니다. @synthesize detailDescriptionLabel;을 방금하면 인스턴스 변수가 동일한 이름을 가졌음을 암시 적으로 이해합니다.

+2

사용자 코드는 앞의 밑줄 문자를 사용하지 않아야합니다. http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/NamingBasics.html#//apple_ref/doc/uid/20001281 -1002931-BBCFHEAB –

+2

사실입니다. 하지만 Xcode 4의 인터페이스 빌더에서 생성 된 코드를 살펴 보았습니다. 대부분의 경우 밑줄을 추가합니다. –

+0

알았어. 감사. 이상하게도 새 Xcode는 이름을 동일하게 유지하는 데 사용되지만 기본 코드는 인스턴스 변수의 이름을 – user544359

0

해당하는 .m에

UILabel *_detailDescriptionLabel; 
} 
    @property (strong, nonatomic) IBOutlet UILabel *detailDescriptionLabel; 

을있는 .h

이 줄 재산 "detailDescriptionLabel는"

"_detailDescriptionLabel"라는 이름의 클래스 속성에 대한 세터와 게터가된다는 것을 의미합니다
@synthesize detailDescriptionLabel = _detailDescriptionLabel; 

이름이 같은 경우

@synthesize detailDescriptionLabel;