10

i have this enum:

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

and want to store it along with some other variables using the nscoding protocol

- (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
}

What coder method do i use to decode and encode this kind of enum?

1
  • 2
    decodeInt/encodeInt (with some casting). Commented Jan 31, 2013 at 9:53

1 Answer 1

5

Generally speaking the representation of enums can vary. When working with Objective-C, you should use the NS_ENUM macro to be sure of which type is used to represent the enumeration. There's more background in this article.

Sign up to request clarification or add additional context in comments.

2 Comments

This is the drawback of putting links as answer. You can never tell when they would start showing 404 :(
Most blog articles from Big Nerd Ranch were moved. Here is the new url: bignerdranch.com/blog/enum-num-num

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.