Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Where are the presidents?

I've worked through the various exercises in the book without any major issues until Chapter 9. But I cannot get the presidents to show up in the BIDPresidentsViewController. The format of presidents.plist does not seem to match the logic used in the initWithNibName: method to read it. 

I tried building the version in the source code archives and that one has the same problem.

Has anyone gotten this to work? What am I missing?

Thanks,
Jeff

Comments

  • The presidents are unfortunately corrupted in the large source code zip. Download an updated chapter 9 project here: http://learncocoa.org/Chapter_09_b.zip.

    Sorry for the inconvenience. 

    // Fredrik
  • I've also updated the full source archive to contain the fixed version:


    //jack
  • I attempted to use the updated plist from the link in @PeyloW 's comment, but I'm running into the same problem.  Can you please confirm that this archive is fixed?  Thanks. 
  • If you are running the application from the new download it works. On the other hand I have been unsuccessful in getting the new presidents plist file to run in my own project (ran clean,clean build folder,cleared out the derived data in organiser and projects) updated the plist file itself to replace "BID" class prefixes with my own prefix (two entries in the file). The only outstanding question I have is the decodeObjectForKey call to the root string "Presidents" - this string doesn't exist in the plist file (President singular is what is contained there) - unless its referring to the name of the file (I would doubt) or its just a root key that was used when the archive was created and is hidden in the file - I don't know if this is the reason or not but have given up on trying to figure this out myself.
  • edited February 2013
    I would not recommend trying to edit the Presidents.plist file manually. It is probably a mistake to name it with the plist file extension, and should be changed in a future edition of the book.

    The problem is that the built in Xcode 4.x plist editor can not fully handle the keyed archivers plist file. If you try to view the plist file from Finder with Quicklook you will notice that at the bottom of the file there is a key named $top containing a dictionary with Presidents as the key. This value is not visible at all in Xcode's plist editor, and if you edit the file from Xcode this invisible data will be removed and the plist is now corrupt.

    // Fredrik
  • thanks Peylow, guessed as much. as there are two entries in the file specifying the class type eg.$classname BIDPresident (reading from Xcode so there probably could be more!) I suppose that maintaining the same class pre-fix in the code (indeed the exact name of the class) is a pre-condition to using the file also. thanks for the explanation.
  • Exact names is not a strict requirement, but knowing the name as it was archived is. The NSKeyedUnarchiver class have functionality for translating classes if you would need to rename them. The easiest method would be to register a class translation like this:
       [NSKeyedUnarchiver setClass:[BIDNewClassName class] 
                      forClassName:@"BIDOldClassName"];
    See the documentation for NSKeyedUnarchiver for a full explanation.

    // Fredrik
  • I also had the problem of the missing presidents. Downloaded the new Presidents.plist file, but no luck.

    Turns out that I had a problem with declaring my President class. I used copy and paste a lot in the encodeWithCoder and initWithCoder and forgot to change the constants.

    After I did that, the presidents returned using both the old and the new plists.
  • I just got the same problem with the missing presidents.

    So is there a way to fix that issue ? I wish i could see that last section running to exactly see how does it work...

  • Yes, there is.

    Method 1:
    As mentioned by PeyloW, u can use the code:
       [NSKeyedUnarchiver setClass:[BIDNewClassName class] 
                      forClassName:@"BIDOldClassName"];

    on the "PresidentsViewController.m" after this code:
               unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];


    Method 2:
    Change the Presidents.plist file using TextWrangler.

            </dict>
            <string>George Washington</string>
            <string>1789</string>
            <string>1797</string>
            <string>None</string>
            <dict>
                <key>$classes</key>
                <array>
                    <string>BIDPresident</string>
                    <string>NSObject</string>
                </array>
                <key>$classname</key>
                <string>BIDPresident</string>     --->  Change "BIDPresident" to the class name as you named in your XCode project. For example, I named it as President.h and President.m in XCode..So, here I changed to President instead of BIDPresident.
            </dict>


    I had tested on both method and they worked, perhaps you would like to had a try on yours. =)
Sign In or Register to comment.