Object C 언어의 변수선언 중 필수적으로 알아야 할 사항이다!.
우선 사용 방법은 다음과 같다.
---> Header File // // GreenViewController.h // LotationTest // // Created by jjangdali on 2014. 1. 9.. // Copyright (c) 2014년 jjangdali. All rights reserved. // #import <UIKit/UIKit.h> @interface GreenViewController : UIViewController { NSString *userID; } @property (strong, nonatomic) NSString *userID; @end |
---> Source File // // GreenViewController.m // LotationTest // // Created by jjangdali on 2014. 1. 9.. // Copyright (c) 2014년 jjangdali. All rights reserved. // #import "GreenViewController.h" @interface GreenViewController () @end @implementation GreenViewController @synthesize userID; @end |
@property 는 외부에서 객체에 접근하기 위해 선언하는 것이다.
클래스 내부에서만 사용하는 변수인 경우에는 property를 사용하지 않는다.
property 로 선언한 변수는 클래스 내부의 전역 변수와 아무런 관련이 없으며(독립적이라고 보면 된다.)
헤더에서는 이러한 변수가 존재한다. 라는 정도의 의미로 사용된다.
@synthesize 는 헤더파일에서 정의한 것을 소스파일에서 실체화 하는 것이다.
synthesize를 선언하게 되면 내부에 전역변수를 만든다.(if 같은 이름의 변수가 있다면 그대로 사용한다.)
getter 함수과 setter 함수를 만든다. (setter함수는 property가 readonly로 설정되지 않은 경우에만)
@property에 대한 참고사항
|
'Computer Programming > Object C' 카테고리의 다른 글
[ObjectC]ios GooglePlus Login 구현하기 /GooglePlus SDK (0) | 2014.01.20 |
---|---|
[ObejctC]InterOP(ios 어플리케이션간 통신 방법) (0) | 2014.01.20 |
[ObjectC]ios Facebook SDK Login 구현 (0) | 2014.01.17 |
[ObjectC]object C 기본 문법 정리 (0) | 2014.01.10 |
[ObjectC]prepareForSegue 사용하여 다음 view로 데이터 넘기기 (0) | 2014.01.09 |