Amazon.com Widgets Program 19.7 (pp. 444-5) will not decode AddressCard objects
Welcome, Guest. Please login or register.
Did you miss your activation email?
July 23, 2014, 11:25:25 PM
Home Help Search chat Login Register 
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+ Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+ Old Stuff
| |-+ Chapter Study
| | |-+ Chapter 19 - Archiving
| | | |-+ Program 19.7 (pp. 444-5) will not decode AddressCard objects
Pages: [1] Go Down
Print
Author Topic: Program 19.7 (pp. 444-5) will not decode AddressCard objects (Read 1147 times)
Pneumatikon
Newbie
*
Posts: 3






on: March 16, 2010, 07:01:00 AM

I've combined 19.6 and 19.7, and I've typed the AddressCard.h/.m and AddressBook.h/.m files out almost exactly as in the book (though my AddressCard objects have more fields), and I can't figure out how to fix the problem. As you can see from the output below the AddressCard objects are coding just fine, but when the AddressBook is decoded it's book database is empty:

AddressCard[3245:80f] ============== Contents of: Steve's Address Book ==============
2010-03-16 08:46:31.779 AddressCard[3245:80f] Baker, Jamie    jbaker@kochan-wood.com   (312) 408-6790
2010-03-16 08:46:31.780 AddressCard[3245:80f] Ianinno, Tony    tony.iannino@techfitness.com   (312) 490-0406
2010-03-16 08:46:31.781 AddressCard[3245:80f] Kochan, Julia    jewls337@axlc.com   (312)419-8030
2010-03-16 08:46:31.782 AddressCard[3245:80f] Kochan, Stephen    steve@kochan-wood.com   (312) 408-9360
2010-03-16 08:46:31.782 AddressCard[3245:80f] Krapek, Bill    xxxxxxxxxx   xxxxxxxxxx
2010-03-16 08:46:31.783 AddressCard[3245:80f] =====================================================
2010-03-16 08:46:31.785 AddressCard[3245:80f] Jamie Baker encoded
2010-03-16 08:46:31.785 AddressCard[3245:80f] Tony Ianinno encoded
2010-03-16 08:46:31.786 AddressCard[3245:80f] Julia Kochan encoded
2010-03-16 08:46:31.787 AddressCard[3245:80f] Stephen Kochan encoded
2010-03-16 08:46:31.788 AddressCard[3245:80f] Bill Krapek encoded
2010-03-16 08:46:31.790 AddressCard[3245:80f] ============== Contents of: Steve's Address Book ==============
2010-03-16 08:46:31.791 AddressCard[3245:80f] =====================================================


Here's the relevant code (I think) in AddressCard.m:

- (void) encodeWithCoder:(NSCoder *) encoder {
   [encoder encodeObject: firstName forKey: @"AddressCardFirstName"];
   [encoder encodeObject: lastName forKey: @"AddressCardLastName"];
   [encoder encodeObject: email forKey: @"AddressCardEmail"];
   [encoder encodeObject: phoneNumber forKey: @"AddressCardPhoneNumber"];
   NSLog(@"%@ %@ encoded", firstName, lastName);
}

- (id) initWithCoder:(NSCoder *) decoder {
   NSLog(@"decoding an addresscard");
   firstName = [[decoder decodeObjectForKey: @"AddressCardFirstName"] retain];
   lastName = [[decoder decodeObjectForKey: @"AddressCardLastName"] retain];
   email = [[decoder decodeObjectForKey: @"AddressCardEmail"] retain];
   phoneNumber = [[decoder decodeObjectForKey: @"AddressCardPhoneNumber"] retain];
   NSLog(@"%@ decoded", firstName);
   
   return self;
}


I've got an NSLog at the top of initWithCoder, and I can tell from that that the functions not even being called.

Here's where I archive and dearchive:

if ([NSKeyedArchiver archiveRootObject: myBook toFile: @"addrbook.arch"] == NO)
      NSLog(@"archiving failed");
   
AddressBook *secondBook = [NSKeyedUnarchiver unarchiveObjectWithFile: @"addrbook.arch"];
   
[secondBook list];
Last Edit: March 16, 2010, 07:07:30 AM by Pneumatikon Logged
skochan
Administrator
Hero Member
*****
Posts: 3114







Reply #1 on: March 16, 2010, 07:31:12 AM

Hi,

Can I see you archiving methods from the AddressBook class?

Cheers,

Steve
Logged
Pages: [1] Go Up
Print
Jump to:



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.