1. 특정주기로 발생하는 타이머 (즉시 동작)
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(onTick) userInfo:nil repeats:YES];

호출 후 부터 1초마다 self 의 onTick 을 인자값 없이 반복 호출

2. 특정주기로 발생하는 타이머 (시작시간 조절)
[[NSRunLoop currentREunLoop] addTimer:[[[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:0.0] interval:9.0 target:self selector:@selector(onTick) userInfo:nil repeats:YES] autorelease] forMode:NSDefaultRunLoopMode];

1번과 유사한 동작이지만 initWithFireDate 에 명시한 시간부터 onTick 이 호출된다.
여기서는 dateWithTimeIntervalSinceNow:0.0 으로 즉시 onTick 이 호출되고, 이후 1초마다 호출된다. 
NSMutableDicrionary 를 상속받아서 사용시에 몇가지 abstract method 를 구현해주어야 한다. 그렇지 않고 사용시 "method only defined for abstract class" 라는 디버깅 메세지를 만날 것이다.

다음은 override 해야할 method 들이다.

1. NSMutableDicrionary
 
2. NSDicrionary

클래스 레퍼런스를 링크하였으니 각 클래스 레퍼런스의 "Overview" 에 "Subclassing notes" 를 참고하면 된다. 이외의 다른 클래스들은 애플 개발자 사이트 (https://developer.apple.com/) 를 참고.

--------

추가. (2012/06/14) Class Cluster 에 대한 이해가 필요한 것이다.



'Mobile > iOS' 카테고리의 다른 글

UIImage 자르기  (0) 2012.03.20
[iOS] NSTimer 사용  (0) 2012.03.13
[Simul] 시뮬레이터에서 멀티터치 테스트  (0) 2012.02.28
[iOS] CoreData 추가하기  (0) 2012.02.24
[iOS] CFOptionFlags  (0) 2012.02.21
OPT 키를 누르면 포인트 점 2개가 나타난다.
이후 클릭시 두군데를 동시에 누른것처럼 동작한다. 
1. Frameworks 에 CoreData.framework 추가.
2. Data Model 파일 (<Project-Name>.xcdatamodeld) 추가.
3. <Project-Name>.pch 에 "#import <CoreData/CoreData.h>" 추가. (위치는 눈치봐서 맞춰서 넣을 것)
4. AppDelegate 선언부에 다음을 추가.

@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;

- (NSURL *)applicationDocumentsDirectory; 



5. AppDelegate 구현부에 다음을 추가. <Project-Name> 이 두군데 있으니 잘 찾아서 수정.

#pragma mark - Core Data stack

/**
 Returns the managed object context for the application.
 If the context doesn't already exist, it is created and bound to the persistent store coordinator for the application.
 */
- (NSManagedObjectContext *)managedObjectContext
{
    if (__managedObjectContext != nil)
    {
        return __managedObjectContext;
    }
    
    NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
    if (coordinator != nil)
    {
        __managedObjectContext = [[NSManagedObjectContext alloc] init];
        [__managedObjectContext setPersistentStoreCoordinator:coordinator];
    }
    return __managedObjectContext;
}

/**
 Returns the managed object model for the application.
 If the model doesn't already exist, it is created from the application's model.
 */
- (NSManagedObjectModel *)managedObjectModel
{
    if (__managedObjectModel != nil)
    {
        return __managedObjectModel;
    }
    NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"<Project-Name>" withExtension:@"momd"];
    __managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
    return __managedObjectModel;
}

/**
 Returns the persistent store coordinator for the application.
 If the coordinator doesn't already exist, it is created and the application's store added to it.
 */
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
    if (__persistentStoreCoordinator != nil)
    {
        return __persistentStoreCoordinator;
    }
    
    NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"<Project-Name>.sqlite"];
    
    NSError *error = nil;
    __persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
    if (![__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error])
    {
        /*
         Replace this implementation with code to handle the error appropriately.
         
         abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 
         
         Typical reasons for an error here include:
         * The persistent store is not accessible;
         * The schema for the persistent store is incompatible with current managed object model.
         Check the error message to determine what the actual problem was.
         
         
         If the persistent store is not accessible, there is typically something wrong with the file path. Often, a file URL is pointing into the application's resources directory instead of a writeable directory.
         
         If you encounter schema incompatibility errors during development, you can reduce their frequency by:
         * Simply deleting the existing store:
         [[NSFileManager defaultManager] removeItemAtURL:storeURL error:nil]
         
         * Performing automatic lightweight migration by passing the following dictionary as the options parameter: 
         [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
         
         Lightweight migration will only work for a limited set of schema changes; consult "Core Data Model Versioning and Data Migration Programming Guide" for details.
         
         */
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }    
    
    return __persistentStoreCoordinator;
}

#pragma mark - Application's Documents directory

/**
 Returns the URL to the application's Documents directory.
 */
- (NSURL *)applicationDocumentsDirectory
{
    return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
}


 

enum CFSocketCallBackType {

kCFSocketNoCallBack = 0,
kCFSocketReadCallBack = 1,
kCFSocketAcceptCallBack = 2,
kCFSocketDataCallBack = 3,
kCFSocketConnectCallBack = 4,
kCFSocketWriteCallBack = 8
};
typedef enum CFSocketCallBackType CFSocketCallBackType;

상수
kCFSocketNoCallBack

어떠한 활동도 콜백이 구성되지 않는다.

iOS 2.0 이상에서 지원.

CFSocket.h 에 선언됨.

kCFSocketReadCallBack

읽을 수 있는 자료가 있거나 새로운 연결 요청이 있을 경우 콜백이 호출된다. 자료는 자동으로 읽어지지 않는다; 콜백은 자료를 읽어야만 한다.

iOS 2.0 이상에서 지원.

CFSocket.h 에 선언됨.

kCFSocketAcceptCallBack

새로운 연결이 자동으로 수락되고 자식 소켓의 CFSocketNativeHandle 포인터를 포함한 데이터와 함께 콜백이 호출될 것이다. 이 콜백은 listening 소켓에서만 사용가능하다.

iOS 2.0 이상에서 지원.

CFSocket.h 에 선언됨.

kCFSocketDataCallBack

백그라운드에서 수신된 데이터를 읽고 이를 포함한 CFData 개체와 함께 콜백이 호출 될 것이다.

iOS 2.0 이상에서 지원.

CFSocket.h 에 선언됨.

kCFSocketConnectCallBack

CFSocketConnectToAddress 또는 CFSocketCreateConnectedToSocketSignature 호출로 백그라운드에서 연결을 시도할 경우 연결이 되었을 때 이 콜백은 이루어집니다. 이경우 데이터 인자는 NULL 이거나, 연결이 실패했을 경우  SInt32 포인터 에러 코드입니다. 이 콜백은 특정 소켓에 대하여 두번 이상 발생하지 않습니다.

iOS 2.0 이상에서 지원.

CFSocket.h 에 선언됨.

kCFSocketWriteCallBack

소켓이 쓰기가능할 때 콜백이 호출된다. 이 콜백은 소켓을 통해 대용량의 데이터를 보내고난 뒤 커널 버퍼에 여유가 생겼을 때 알림을 받기 원할때 유용하다.

iOS 2.0 이상에서 지원.

CFSocket.h 에 선언됨.


1. Storyboard 가져오기

"[iOS] 기기에 맞는 UIStoryboard 찾기" 참고


2. ViewController 생성

이전
[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];

변경
스토리보드에서 해당 ViewController 의 Identifier 를 "ViewController" 로 설정
[storyboard instantiateViewControllerWithIdentifier:@"ViewController"];




'Mobile > iOS' 카테고리의 다른 글

[iOS] CoreData 추가하기  (0) 2012.02.24
[iOS] CFOptionFlags  (0) 2012.02.21
[iOS] 기기에 맞는 UIStoryboard 찾기  (0) 2012.02.20
[iOS] 함수 포인터를 이용하여 핸들러 만들기  (0) 2012.02.20
[iOS] iOS Application Life-cycle  (0) 2012.02.17

1. 스토리보드 이름 찾기

[ProjectName]-Info.plist 파일에서 확인할 수 있다.

iPhone 은 "Main storyboard file base name", iPad 는 "Main storyboard file base name (iPad)" 에서 확인할 수 있다.


2. 기기에 맞는 스토리보드 이름 가져오기

NSString *storyboardName = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad? @"MainStoryboard_iPad": @"MainStoryboard_iPhone");


3. 스토리보드 찾기

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle:nil];

typedef void (^Handler)(int result);
Handler handler = ^(int result) {
    NSLog(@"Handler called by result: %d", result);
};

'Mobile > iOS' 카테고리의 다른 글

[iOS] Storyboard 사용시 ViewController 의 initWithNibName 대응법  (0) 2012.02.20
[iOS] 기기에 맞는 UIStoryboard 찾기  (0) 2012.02.20
[iOS] iOS Application Life-cycle  (0) 2012.02.17
[iOS] boolean type  (0) 2012.02.17
[iOS] Multitasking  (0) 2012.02.17

상태변화시 호출되는 메서드를 정리해보았다.


 

'Mobile > iOS' 카테고리의 다른 글

[iOS] 기기에 맞는 UIStoryboard 찾기  (0) 2012.02.20
[iOS] 함수 포인터를 이용하여 핸들러 만들기  (0) 2012.02.20
[iOS] boolean type  (0) 2012.02.17
[iOS] Multitasking  (0) 2012.02.17
[iOS] Gesture Recognizer  (0) 2012.02.16

bool 을 치면 Code Completion 에 "BOOL", "bool", "Boolean", "boolean_t" 네개가 뜬다.
궁금해서 찾아보았다.

1. BOOL (iPhoneOS5.0 > usr/include > objc > objc.h)
   typedef signed char BOOL;

2. bool (stdbool.h)
    #define bool _Bool

3. Boolean (iPhoneOS5.0 > usr/include > MacTypes.h)
    typedef unsigned char Boolean;

4. boolean_t (iPhoneOS5.0 > usr/include > mach > arm > boolean.h)
    typedef int boolean_t;


_Bool 은 Symbol 을 찾을 수 없다고 나와 무엇인지 모르겠다.

'Mobile > iOS' 카테고리의 다른 글

[iOS] 함수 포인터를 이용하여 핸들러 만들기  (0) 2012.02.20
[iOS] iOS Application Life-cycle  (0) 2012.02.17
[iOS] Multitasking  (0) 2012.02.17
[iOS] Gesture Recognizer  (0) 2012.02.16
[iOS] Touches  (0) 2012.02.16

+ Recent posts