iOS/Xcode

전역변수 사용하기

띠오링 2012. 6. 23. 23:36

출처 : http://thefermata.net/?p=607


[ObjC] 전역변수 사용하기


일반적으로 숫자와 관련된 어플리케이션 (과연 숫자를 사용하지 않는 프로그램이 있을까?)를 프로그래밍 할때면 전역변수만큼 유용한것이 없다.
인터넷을 찾아보니 Objective C에서 전역변수를 사용하는 방법은 php만큼 쉬웠다.

//Global_Variable.h (헤더파일)
//쏼라쏼라~~ :P
//extern (자료형) (변수명)
extern NSInteger sampleInteger;

//Global_Variable.m (소스파일)
#import! “Global_Variable.h”;
NSInteger sampleInteger = 0; //변수값 초기화해주고
@implementation Global_Variable
-(void)increaseInteger
{
sampleInteger++;
}
@end