2011년 3월 29일 화요일

아이폰개발:유용한 매크로...

<<성능측정>>
#define BM_START(name) NSDate *name##_start = [NSDate new]
#define BM_END(name) NSDate *name##_end = [NSDate new];\
NSLog(@"%s interval: %f", #name, [name##_end timeIntervalSinceDate:name##_start]);\
[name##_start release];[name##_end release]

#define GET_USER_NAME() [MSStringUtil stringByTrimmingSpaceWithString: [[[[KISDocument sharedKISFDocument] settings] loginData] objectAtIndex:2]]

#define GET_USER_ID() [MSStringUtil stringByTrimmingSpaceWithString: [[[KISDocument sharedKISFDocument] settings] loginID]]


#define GET_APP_DELEGATE() (ZZZZZAppDelegate *)[[UIApplication sharedApplication] delegate]

#define PUSH_VIEW_CONTROLLER(controller) controller *target = \

[[controller alloc] initWithNibName:@#controller bundle:nil]; \

[self.navigationController pushViewController:target animated:YES];\

[target release];


//내비게이션 컨트롤러 내에서 있다면 ...

#define JUMPTO(controller) NSArray *arr = self.navigationController.viewControllers;\

NSEnumerator *enumerator = [arr objectEnumerator];\

id anObject;\

NSInteger toIdx = 0;\

while (anObject = [enumerator nextObject]) {\

if ([anObject isKindOfClass:[controller class]]) {\

toIdx = [arr indexOfObject:anObject];\

break;\

}\

}\

[self.navigationController popToViewController:anObject animated:YES];


//로그인 컨트롤러, 로그인 성공시에 이동할 뷰컨트롤러

#define LOGIN_TITLE_TARGET(controller,target) controller *login = \

[[controller alloc] initWithNibName:@#controller bundle:nil]; \

login.doCertificateLogin = YES; \

target *tg = [[target alloc] initWithNibName:@#target bundle:nil]; \

[login setDestination:(target*)tg];\

[self.navigationController pushViewController:login animated:YES];\

[tg release];\

[login release];


//Singletone

#define SYNTHESIZE_SINGLETON_FOR_CLASS(classname) \

\

static classname *shared##classname = nil; \

\

+ (classname *)shared##classname \

{ \

@synchronized(self) \

{ \

if (shared##classname == nil) \

{ \

shared##classname = [[self alloc] init]; \

} \

} \

\

return shared##classname; \

} \

\

+ (id)allocWithZone:(NSZone *)zone \

{ \

@synchronized(self) \

{ \

if (shared##classname == nil) \

{ \

shared##classname = [super allocWithZone:zone]; \

return shared##classname; \

} \

} \

\

return nil; \

} \

\

- (id)copyWithZone:(NSZone *)zone \

{ \

return self; \

} \

\

- (id)retain \

{ \

return self; \

} \

\

- (NSUInteger)retainCount \

{ \

return NSUIntegerMax; \

} \

\

- (void)release \

{ \

} \

\

- (id)autorelease \

{ \

return self; \

}


댓글 없음:

댓글 쓰기