@interface
@interface Patient : NSObject <NSCoding>
@implementation
- (id)initWithCoder:(NSCoder *)decoder{
self.patientPhoto = [decoder decodeObjectForKey:kPatientPhoto];
self.firstName = [decoder decodeObjectForKey:kFirstName];
self.lastName = [decoder decodeObjectForKey:kLastName];
self.age = [decoder decodeIntForKey:kAge];
self.photoPaths = [decoder decodeObjectForKey:kPhotoPaths];
self.photoDates = [decoder decodeObjectForKey:kPhotoDates];
return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder{
[encoder encodeObject:self.patientPhoto forKey:kPatientPhoto];
[encoder encodeObject:self.firstName forKey:kFirstName];
[encoder encodeObject:self.lastName forKey:kLastName];
[encoder encodeInt:self.age forKey:kAge];
[encoder encodeObject:self.photoPaths forKey:kPhotoPaths];
[encoder encodeObject:self.photoDates forKey:kPhotoDates];
}
In a different implementation I attempt to archive the Patient Object.
IMDataController* dataCtr = [IMDataController sharedDataController];
Patient *currentPatient = [[Patient alloc]init];
currentPatient.patientPhoto = self.photo.image;
currentPatient.firstName = self.firstName.text;
currentPatient.lastName = self.lastName.text;
currentPatient.age = [self.lastName.text intValue];
currentPatient.photoDates = nil;
currentPatient.photoPaths = nil;
NSString *patientNameForWriting = [self.firstName.text stringByAppendingString:self.lastName.text];
NSString *stringToPatientObjectFile = [dataCtr createPatient:patientNameForWriting];
NSFileManager* filemanager = [NSFileManager defaultManager];
NSData *patientObjectArchived = [NSKeyedArchiver archivedDataWithRootObject:currentPatient];
if([patientObjectArchived writeToFile:stringToPatientObjectFile atomically:YES]){
}else{
NSLog(@"Patient Object Didn't Archive");
}
The above method within the if statement is not returning YES. I have checked the data against nil, I have checked my encoder method and I cannot find the problem. I am writing the data to a NSString file Path:.../Documents/PatientName/PatientObject.archive. I am conforming to the protocol in the patient class also.