PDA&Mobile2010.03.30 11:32
* 본 포스트는 Blog.MissFlash.com에서 작성한 것으로, 원문 저작자의 동의없이 마음대로 퍼가실 수 없습니다. 포스트의 내용이 마음에 드시면 링크를 이용해주시면 감사하겠습니다.

> Head First iPhone Development 정리 #3

Chapter 3. objective-c for the iPhone - Twitter needs variety

@property(in the .h file) & @synthesize(in the .m file) : tell Objective-C to autogenerate getter and setter methods.

-(The minus sign) : it's an instance method.
+(The plus sign) : it's an class method(at means it's static).

Property attributes and definitions
  • readonly : When you don't want people modifying the property. You can still change the field value backing the property, but the compiler won't generate a setter.
  • readwrite : When you want the property to be modifiable by people. The compiler will generate a getter and a setter for you. This is the default.
  • copy : When you want to hold onto a copy of some value instead of the value itself; for example, if you want to hold onto an array and don't want people to be able to change its contents after they set it. This sends a copy message to the value passed in then retains that.
  • retain : When you're dealing with object values. The compiler will retain the value you pass in and release the old value when a new one comes in.
  • assign : When you're dealing with basic types, like ints, floats, etc. The compiler just creates a setter with a simple myField = value statement. This is the default, but not usually what you want.
  • atomic : Locks, Generated accessors are multithread safe and use mutexes when changing a property value. (cf. nonatomic : unlocks)

Example
  • retain : @ property (nonatomic, retain) NSString* myField;
- (NSString*) myField{
    return myField;
}
- (void)setMyField:(NSString *) newValue{
    if(newValue != myField){
        [myField release];
        myField = [newValue retain];
    }
}

  • assign : @ property (nonatomic, assign) NSString* myField; (Unproper to the NSString!!!)
- (NSString*) myField{
    return myField;
}
- (void)setMyField:(NSString *) newValue{
    myField = newValue;
}

To keep your memory straight!!!
  1. You must release objects you create with allocnewcopy, or mutableCopy.
  2. Consider everything else to have a retain count of 1 and in the autorelease pool.

TextField Done Editing

- (IBAction)textFieldDoneEditing: (id)sender

{

    [sender resignFirstResponder]; 

}


이미지 출처 : flickr.com

저작자 표시 비영리 변경 금지
신고

이 글은 새로운 정보가 추가될 때마다 업데이트됩니다. 추천으로 아래 숫자에 1을 더해보세요. :)
RSS구독을 하시면 포스트를 배달해 드립니다. ▷ 한RSS 구독하기, 구글리더 구독하기

댓글을 달아 주세요

  1. Favicon of http://www.thenorthfaceab.com/ BlogIcon north face outlet

    관리자의 승인을 기다리고 있는 댓글입니다

    2013.01.05 01:38 [ ADDR : EDIT/ DEL : REPLY ]


티스토리 툴바