I have a class called Account with 6 properties and one of the properties is a c struct. I can't figure out how to use NSCoding to comply with the struct. How would I go about encoding and decoding the c struct property. The struct is the type app_config_t.
the struct
typedef struct app_config_t
{
pj_pool_t *pool;
pjsua_config cfg;
pjsua_logging_config log_cfg;
pjsua_media_config media_cfg;
pjsua_transport_config udp_cfg;
pjsua_transport_config rtp_cfg;
pj_bool_t ringback_on;
pj_bool_t ring_on;
int ringback_slot;
int ringback_cnt;
pjmedia_port *ringback_port;
int ring_cnt;
SystemSoundID ring_id;
CFRunLoopTimerRef ring_timer;
} app_config_t;
An Objective-C class called 'Account' with property App_config
#pragma mark - NSCoding
- (void) encodeWithCoder:(NSCoder *)aCoder
{
[aCoder encodeObject:self.Username forKey:@"username"];
[aCoder encodeObject:self.Password forKey:@"password"];
[aCoder encodeObject:self.Server forKey:@"server"];
[aCoder encodeInt:self.Account_id forKey:@"Account_id"];
[aCoder encodeInt:self.Call_id forKey:@"Call_id"];
//trying to save this object, is this even correct
NSMutableData *data = [NSMutableData dataWithBytes:&_App_config length:sizeof(app_config_t)];
NSKeyedArchiver *App_config_Archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
[aCoder encodeObject:App_config_Archiver forKey:@"App_config"];
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
if (self = [super init])
{
self.Username = [aDecoder decodeObjectForKey:@"username"];
self.Password = [aDecoder decodeObjectForKey:@"password"];
self.Server = [aDecoder decodeObjectForKey:@"server"];
self.Account_id = [aDecoder decodeIntForKey:@"Account_id"];
self.Call_id = [aDecoder decodeIntForKey:@"Call_id"];
self.App_config = ?????????
}
return self;
}