Folks,
I'm trying to array of objects to pList by using NSCoder class. I can save some direct objects to the plist. For Ex: I've class called 'ExClass' with Sample(NSString) property. Now i could save a collection of 'ExClass' object to pList file. Now I'm trying this, but i'm getting an exception
Example:
Class FirstName
{
NsString *first_name;
}
Class LastName
{
NsString *last_name;
}
Class Name: FirstName, LastName
{
FirstName *first;
LastName *last;
}
Now I would like to save a collection of name, which should have both first and last name into it. I tried by this way
.h File:
#import "Name.h"
@interface sample : NSObject <NSCoding>
@property (nonatomic, strong) Name *name;
@end
.m File:
#import "sample.h"
@implementation sample
@synthesize name;
- (id)initWithCoder:(NSCoder *)aDecoder
{
if(self = [super init]) {
self.name = [aDecoder decodeObjectForKey:@"Name"];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder
{
self.name = [encoder encodeObject: self.first forKey:@"Name"];
}
@end
I got an exception, which says that, "Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Name encodeWithCoder:]: unrecognized selector sent to instance".
Guys please help on this