I have a view in my app that shows a form (email, first name, last name, date of birth) which loads into the fields, the corresponding data from the keychain allowing the user to change it etc. This works fine when there are already details stored in the keychain, but if there is nothing (when the app is run for the first time) it crashes when I go to release the keychain. In order to save a memory leak, I want to see if there is a better way of doing things. Im using apple's KeychainItemWrapper and my project does not use ARC.
Here is my code
// add data from keychain to fields if set
KeychainItemWrapper *keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:@"test" accessGroup:nil];
NSString *error;
NSData *dictionaryRep = [keychainItem objectForKey:kSecAttrService];
NSDictionary *dictionary = [NSPropertyListSerialization propertyListFromData:dictionaryRep mutabilityOption:NSPropertyListImmutable format:nil errorDescription:&error];
if (error) {
NSLog(@"An error occurred - %@", error);
}
else{
//successful so populate fields
email_.text = [dictionary objectForKey:@"email"];
firstName_.text = [dictionary objectForKey:@"firstname"];
lastName_.text = [dictionary objectForKey:@"lastname"];
dob_.text = [dictionary objectForKey:@"dob"];
}
[keychainItem release]; // crashes here with an EXC_BAD_ACCESS