0

I'm experiencing this crash in my application and I can't seem to figure out what is going wrong.

I've got an object with a property that holds on to a Class struct. I declare it like this:

@property (nonatomic, assign) Class myClass; 

Now, I'd like to serialize this object, so implemented NSCoding. That looks like this:

- (id)initWithCoder:(NSCoder *)coder
{
    self = [super init];
    self.myClass = NSClassFromString([coder decodeObjectForKey:@"myClass"]);
    self.title = [coder decodeObjectForKey:@"title"];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)coder
{
    [coder encodeObject:NSStringFromClass(self.myClass) forKey:@"myClass"];
    [coder encodeObject:self.title forKey:@"title"];
}

However, when I execute this line

    [coder encodeObject:NSStringFromClass(self.myClass) forKey:@"myClass"];

I get an EXC_BAD_ACCESS crash and I am struggling to find out why. Any ideas?

Thanks!

4

0 回答 0