Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 31st, 2011, 08:42 AM
Friend of Wrox
 
Join Date: Aug 2010
Posts: 298
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
 
Old March 31st, 2011, 11:29 AM
Wrox Author
 
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





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 09:41 AM
Chapter 10 czambran BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 2 March 29th, 2005 09:35 AM
Chapter 10 columbiasmiles JSP Basics 0 May 17th, 2004 08:09 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.