Amazon.com Widgets Foo retrieval from archive in 19.10 fails
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 25, 2013, 10:04:56 AM
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
|-+  Programming in Objective-C, 4th edition
| |-+  Chapter 19
| | |-+  Foo retrieval from archive in 19.10 fails
Pages: [1]   Go Down
Print
Author Topic: Foo retrieval from archive in 19.10 fails  (Read 1128 times)
HalS
Newbie
*
Posts: 7






« on: April 28, 2012, 07:39:06 PM »

Hi,
I've been trying to get the program pair in 19.9 and 19.10 to store and recover the archived AddressBook and Foo objects. The AddressBook object does work, but the Foo
retrieval seems to give a range error. Looking at myArchive shows both are in the file and the containsValueForKey method does know the Foo object is in the file. It sounds like I might have some sort of sizeof error with the 4 byte int and 4 byte float, but who knows?
Help?

I have an Intel iMac running Lion with the latest Xcode. The unarchive (1910) program fails at

            myFoo1 = (Foo *)[unarchiver decodeObjectForKey: @"myfoo1"];

without triggering a break at the start of initWithCoder method in Foo.m

output ends with:
2012-05-02 09:05:47.973 Chap19.10[1583:403] *** Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: '*** -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (Foo)'
*** First throw call stack:
(
   0   CoreFoundation                      0x00007fff8e2abfc6 __exceptionPreprocess + 198
   1   libobjc.A.dylib                     0x00007fff906abd5e objc_exception_throw + 43
   2   CoreFoundation                      0x00007fff8e2abdfa +[NSException raise:format:arguments:] + 106
   3   CoreFoundation                      0x00007fff8e2abd84 +[NSException raise:format:] + 116
   4   Foundation                          0x00007fff9640f729 _decodeObjectBinary + 2714
   5   Foundation                          0x00007fff9640ead6 _decodeObject + 201
   6   Chap19.10                           0x00000001062e9108 main + 424
   7   Chap19.10                           0x00000001062e8f54 start + 52
)
terminate called throwing an exception(lldb)
« Last Edit: May 01, 2012, 02:07:14 PM by HalS » Logged
happyzhb
Administrator
Newbie
*****
Posts: 47


Email




« Reply #1 on: May 11, 2012, 09:41:00 AM »

I will take a look at the code later, but here are three questions:
1. can you try to clean all targets "product -> clean" and re-run?
2. are you running the code from the book, any modifications?
3. is foo object archived programmatically (Is this a word, btw)?

Logged
HalS
Newbie
*
Posts: 7






« Reply #2 on: May 11, 2012, 07:00:45 PM »

Thanks for sparing the time. I am totally flummoxed (is that a word??Smiley

1. Product -> clean has no effect. Same result afterwards.
2. Always trivial differences.

I have another card in the address book.

I fully specify the path to myArchive in both programs (but note that the
address book successfully unarchives.

My Foo class files look like the book.

3. I am using the keyed object archiving in 19.9 and 19.10  examples.
Logged
happyzhb
Administrator
Newbie
*****
Posts: 47


Email




« Reply #3 on: May 13, 2012, 07:04:13 PM »

Ok, got them. Haven't got time to run the code yet, but I will do as soon as possible. Cheers.
Logged
HalS
Newbie
*
Posts: 7






« Reply #4 on: May 13, 2012, 11:40:50 PM »

Thanks.

I suspect the unarchiver doesn't see an object of the right length when it goes to pick it up.

Cheers.
« Last Edit: May 14, 2012, 02:10:09 PM by HalS » Logged
happyzhb
Administrator
Newbie
*****
Posts: 47


Email




« Reply #5 on: May 14, 2012, 07:22:04 PM »

Ok, I run the codes in the book, archive the data and then read back and unarchived them. Got the Foo object without any problem.

I am using the latest xcode 4.3 on a lion os.

I suspect your archiving process was not complete correctly. Try to do that and unarchive again.

Or, upload your xcode project here, I'll see if I can reproduce your error.

Logged
HalS
Newbie
*
Posts: 7






« Reply #6 on: May 14, 2012, 10:03:40 PM »

Attached is a zip of my files to generate example 19.9. I've included the 881 byte myArchive file produced by my version of the program.

I apologize for the hacked look of things since I kept trying various things.

I haven't included my version of 19.10. If you see no differences in output from 19.9, then we can move on from there. (perhaps send me your version of myArchive).
Logged
happyzhb
Administrator
Newbie
*****
Posts: 47


Email




« Reply #7 on: May 19, 2012, 06:33:38 AM »

HalS,
I got a chance to try unarchiving with your version of myArchive. It worked just fine. So I attached my program files, you just need to change the path (in my code it is "/Users/haibo/Desktop/myArchivehals" in main.m) to point to your archive file and run, it should unarchive both address book and foo objects with out any problem.

Let me know if it works for you.

Logged
HalS
Newbie
*
Posts: 7






« Reply #8 on: May 19, 2012, 03:12:57 PM »

Still fails using your code. I decode the address book correctly and Foo keels over.
Most curious.

BUT ---- your code works if I generate a new project using just your files. Thus, the problem is that the project definition or some of the files have gotten corrupted somehow.

Either way, the problem is resolved. If it doesn't work --- my fault. Smiley

Thanks for your help.

Adding a little more info to the problem. When I replaced my Foo.m by yours, my code then unarchived foo. The only obvious difference between mine and yours is that the variable names are not colored by the syntax colorer.


« Last Edit: May 19, 2012, 10:22:40 PM by HalS » Logged
happyzhb
Administrator
Newbie
*****
Posts: 47


Email




« Reply #9 on: May 20, 2012, 07:45:59 AM »

Mmm, that's weird, the only think I can think of maybe encoding, for example, if I type letters encoded as "Chinese" it displays as the correct variable, but may not be highlighted.

But as long as the code works and the logic is clear, I agree, we don't have to worry about it. Cheers.
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.