구현 섹션의 중간에 선언 하시겠습니까? 또는 @ ... @end 블록 밖에서도? 그렇다면 글로벌하게 만들었습니다. 오브젝티브 C 아래 개인 인스턴스 변수의 안시 C.
이 때문이 가능합니다 다음을 수행하십시오 MyClassName.h 파일 :
@interface MyClassName : ItsSuperclassName <SomeProtocol> {
float nitriteLevel;
}
// if you want it private then there is no need to declare a property.
@end
MyClasseName.m 파일 :
@implementation
// These days there is no need to synthesize always each property.
// They can be auto-synthesized.
// However, it is not a property, cannot be synthesized and therefore there is no getter or setter.
-(void) someMehtod {
self->nitriteLevel = 0.0f; //This is how you access it.
float someValue2 = self->nitriteLevel; // That is fine.
self.nitriteLevel = 0.0f; // This does not even compile.
[self setNitriteLevel: 0.0f]; //Neither this works.
float someValue2 = self.nitriteLevel; // nope
float someValue3 = [self setNitriteLevel]; // no chance
}
@end
을
다음에 대해 100 % 긍정적 인 것은 아닙니다.이 변수 유형은 자동으로 초기화되지 않습니다. 이 시점에서 float nitriteLevel = 0.0f;
을 사용할 수 없습니다. 초기화 메소드에서 초기화하는지 확인하십시오. stile에 따라 viewDidLoad에서 View Controller의 최신으로 초기화하십시오.
실수로 전역 변수를 만들었습니까? –
변수를 어떻게 선언합니까? 이렇게? '@property (nonatomic) float nitriteLevel;'? – MaxGabriel
위와 같이 선언했으나 (* 속성 또는 비 원자가 없음) 인터페이스와 구현 사이에 선언되었습니다. 이것이 세계화 된 것인가? @implementation 내에서 동일한 동작을 시도해 보았습니다. (Objective-C에는 전역 변수가 없다고 생각 했었습니다.) – user1975122