1. Notifications
1. 원리object가 notification center에 message를 보내면 notification center에 등록된 selector로 해당 메세지를 보내준다.
2. 장단점
다른 object도 해당 message를 볼 수 있다. 즉, 정보를 얻을 수가 있다.
오브젝트간 1:다 관계를 형성할 수 있다.
3. 관련 클래스
NSNotificationCenter
4. 사용법
* 메세제를 받을 수 있도록 설정
[[NSNotificationCenter defaultCenter] addObserver:self selector:@(action:)];
* 센터에 메세지 보내기
[[NSNotificationCenter defaultCenter] postNotificationName:@"MessageName" object:self];
2. Delegates
* 메세제를 받을 수 있도록 설정
[[NSNotificationCenter defaultCenter] addObserver:self selector:@(action:)];
* 센터에 메세지 보내기
[[NSNotificationCenter defaultCenter] postNotificationName:@"MessageName" object:self];
2. Delegates
1. 원리
object와 object의 1:1 관계를 정의하는 패턴이다.
2. 장단점
미리 정의할 수 있는 특정 기능을 수행해야 할 경우에 유용하다. 함수를 호출하는 방식으로 실행된다.
3. Target-Action
1. 예
버튼
2. 사용법
id target = ...; // defined elsewhere
SEL action = ...' // defined elsewhere
[target performSelector:action];
[fileDownloader downloadFile:(NSURL*)url target:(id)target didSucceed:(SEL)succeed didFail:(SEL)failed];
Ref URL
object와 object의 1:1 관계를 정의하는 패턴이다.
2. 장단점
미리 정의할 수 있는 특정 기능을 수행해야 할 경우에 유용하다. 함수를 호출하는 방식으로 실행된다.
3. Target-Action
1. 예
버튼
2. 사용법
id target = ...; // defined elsewhere
SEL action = ...' // defined elsewhere
[target performSelector:action];
[fileDownloader downloadFile:(NSURL*)url target:(id)target didSucceed:(SEL)succeed didFail:(SEL)failed];
Ref URL


