Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional iPhone and iPad Application Development
This is the forum to discuss the Wrox book Professional iPhone and iPad Application Development by Gene Backlin; ISBN: 978-0-470-87819-4
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional iPhone and iPad Application Development section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old March 31st, 2011, 08:42 AM
Friend of Wrox
Points: 1,671, Level: 16
Points: 1,671, Level: 16 Points: 1,671, Level: 16 Points: 1,671, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2010
Posts: 297
Thanks: 1
Thanked 62 Times in 60 Posts
Default Chapter 10

A couple of tweaks that I made to the Property List example:

1. As written, since everything is keyed off of the lastName, it is not possible to have two entries with the same last name, something that is very likely in a "Contacts" program (e.g. family members). All subsequent entries replace prior entries with the same lastName. I resolved this by creating an additional key containing a fullName by appending the firstName to the lastName. Sorting and searching is done by this new key to maintain alphabetic order. When presenting the names in the rootView tableView, if instances of the same name appear more than one time, a first initial is also included. For example:
Jones, J.
Jones, T.
2. In PersonAddViewController I felt some basic validation is a good thing. I added checks to make sure that the input for names was alphabetic throwing up an alert if it was not, and when entering the phone number having the keyboard type switch to the number pad and requiring a valid (U.S.) number of digits. The phone number in the PersonDetailView pane could also be formatted.

In the CoreData version, since everything is stored as a Person entity, there is no issue with multiple same lastName entries. As above, to distinguish matching entries, I also have first initials displayed if multiple entries of the same last name occur. In order to keep things properly sorted when this occurs, I added a second, firstName, sortDescriptor to the fetchedRequestController. I also applied the same validation and formatting as in the Property List example.

In both versions, it does not make sense to have the edit button available if no contacts are in the list. I add it after the first contact is inserted, and remove it should the number of contacts go to 0.

A minor editorial issue which also snuck into the the downloadable source code is a mismatch of keys and fields on p. 340 and again on p. 364 Listing 10-26

Code:
- (void)encodeWithCoder:(NSCoder *)coder {
    [coder encodeObject:[self firstName] forKey:@"firstName"];
    [coder encodeObject:[self lastName] forKey:@"lastName"];
    [coder encodeObject:[self phone] forKey:@"phone"];
}

- (id)initWithCoder:(NSCoder *)coder {
    if (self = [super init]) {
		[self setLastName:[coder decodeObjectForKey:@"firstName"]];
		[self setFirstName:[coder decodeObjectForKey:@"lastName"]];
		[self setPhone:[coder decodeObjectForKey:@"phone"]];
    }
    return self;
}
should be

Code:
- (void)encodeWithCoder:(NSCoder *)coder {
    [coder encodeObject:[self firstName] forKey:@"firstName"];
    [coder encodeObject:[self lastName] forKey:@"lastName"];
    [coder encodeObject:[self phone] forKey:@"phone"];
}

- (id)initWithCoder:(NSCoder *)coder {
    if (self = [super init]) {
		[self setFirstName:[coder decodeObjectForKey:@"firstName"]];
		[self setLastName:[coder decodeObjectForKey:@"lastName"]];
		[self setPhone:[coder decodeObjectForKey:@"phone"]];
    }
    return self;
}
Bob
Reply With Quote
  #2 (permalink)  
Old March 31st, 2011, 11:29 AM
Wrox Author
Points: 362, Level: 6
Points: 362, Level: 6 Points: 362, Level: 6 Points: 362, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2010
Posts: 61
Thanks: 0
Thanked 9 Times in 7 Posts
Default

Quote:
Originally Posted by thepianoguy View Post
A minor editorial issue which also snuck into the the downloadable source code is a mismatch of keys and fields on p. 340 and again on p. 364 Listing 10-26

Code:
- (void)encodeWithCoder:(NSCoder *)coder {
    [coder encodeObject:[self firstName] forKey:@"firstName"];
    [coder encodeObject:[self lastName] forKey:@"lastName"];
    [coder encodeObject:[self phone] forKey:@"phone"];
}

- (id)initWithCoder:(NSCoder *)coder {
    if (self = [super init]) {
		[self setLastName:[coder decodeObjectForKey:@"firstName"]];
		[self setFirstName:[coder decodeObjectForKey:@"lastName"]];
		[self setPhone:[coder decodeObjectForKey:@"phone"]];
    }
    return self;
}
should be

Code:
- (void)encodeWithCoder:(NSCoder *)coder {
    [coder encodeObject:[self firstName] forKey:@"firstName"];
    [coder encodeObject:[self lastName] forKey:@"lastName"];
    [coder encodeObject:[self phone] forKey:@"phone"];
}

- (id)initWithCoder:(NSCoder *)coder {
    if (self = [super init]) {
		[self setFirstName:[coder decodeObjectForKey:@"firstName"]];
		[self setLastName:[coder decodeObjectForKey:@"lastName"]];
		[self setPhone:[coder decodeObjectForKey:@"phone"]];
    }
    return self;
}
Bob

Thanks Bob, I orginally did not have them in the proper order and chose to manually edit them, rather than a simple cut and paste to match the encode and decode. That will teach me
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 10, listing 10-10-app kiwibrit BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9 2 August 18th, 2009 04:21 AM
Chapter 10 gogeo BOOK: Beginning Access 2003 VBA 1 January 22nd, 2006 08:41 AM
Chapter 10 czambran BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 2 March 29th, 2005 08:35 AM
Chapter 10 columbiasmiles JSP Basics 0 May 17th, 2004 08:09 PM



All times are GMT -4. The time now is 11:58 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.