2013-01-31 2 views
9

난이 열거 있습니다NSCoding 프로토콜을 열거 형과 함께 사용하는 방법?

typedef types { 
    HBIntineraryTypeVisited = 0, 
    HBIntineraryTypeUnvisited, 
    HBIntineraryTypeUnknown, 
    HBIntineraryTypeDeleted, 
} HBIntineraryType; 

을하고 nscoding 프로토콜 방법을 코더 무엇

- (id)initWithCoder:(NSCoder *)aDecoder 
{ 
    self = [super init]; 
    if (self) { 
     _name = [aDecoder decodeObjectForKey:@"name"]; 
     // todo decode enum object 
    } 
} 

- (void)encodeWithCoder:(NSCoder *)aCoder 
{ 
    [aCoder encodeObject:_name forKey:@"name"]; 
    // todo encode enum object 
} 

를 사용하여 다른 변수와 함께 그것을 저장할 내가 디코딩 열거의이 종류를 인코딩하는 데 사용합니까?

+1

'decodeInt' /'encodeInt' (일부 캐스팅 포함). – trojanfoe

답변

4

일반적으로 enum의 표현은 다를 수 있습니다. Objective-C로 작업 할 때 열거 형을 나타내는 데 어떤 유형이 사용되는지 확인하려면 the NS_ENUM macro을 사용해야합니다. this article에 더 많은 배경이 있습니다.

+2

이것은 링크를 대답으로 두는 단점입니다. 그들이 404를 보여주기 시작할 때를 결코 알 수 없습니다 : ( – Kaunteya

+0

Big Nerd Ranch의 대부분의 블로그 기사가 옮겨졌습니다. 다음은 새로운 URL입니다 : https://www.bignerdranch.com/blog/enum-num-num/ – Dustt

관련 문제