Wrox Programmer Forums
|
BOOK: Professional iPhone and iPad Database Application Programming
This is the forum to discuss the Wrox book Professional iPhone and iPad Database Application Programming by Patrick Alessi; ISBN: 978-0-470-63617-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional iPhone and iPad Database Application Programming 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 July 13th, 2011, 10:48 PM
Authorized User
 
Join Date: May 2011
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
Default Chapter 2 Product Class Question

I have a couple of question regarding the Product class in chapter 2. Why are some of the the properties retained, while others are not? What is the significance of "nonatomic"?
 
Old July 14th, 2011, 09:06 AM
Friend of Wrox
 
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts
Default

The word retain in the property means that the accessor (setter) generated in the @synthesize will retain the object passed in. If you do not specify 'retain' then the accessor will use 'assign'. For most objects the passed in value is retained (old value released and new value retained). Primitive types like float and int are not objects, so the setter assigns rather than retains the value. The third option is copy, and is not used in the example.

typical retain setters
Code:
-(void)setName:(NSString *)newName
{
	[newName retain];
	[name release];
	name = newName;
}
or

Code:
-(void)setName:(NSString *)newName
{
	[name autorelease];
	name = [newName retain];
}
A typical 'assign'

Code:
-(void)setAmount:(float)newAmount
{
	amount = newAmount;
}
By default the accessors are atomic, they can't be called from two places simultaneously. (a lock is applied) This prevents potential garbage from being produced. nonatomic is faster than atomic since there is no locking/unlocking, and can be used if there is no expectation that there will be simultaneous calls to the same accessor.

Bob

Last edited by thepianoguy; July 15th, 2011 at 06:21 PM..
 
Old July 15th, 2011, 04:47 PM
Authorized User
 
Join Date: May 2011
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks PianoGuy!





Similar Threads
Thread Thread Starter Forum Replies Last Post
A question about abstract class nf0001384 C# 2005 5 July 22nd, 2013 06:58 AM
Question about BizObject class. yevi BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 10 April 16th, 2009 01:12 PM
Question about value class type saadli BOOK: Ivor Horton's Beginning Visual C++ 2008 ISBN: 978-0-470-22590-5 4 December 3rd, 2008 10:15 PM
question about sub New() in class hertendreef ASP.NET 2.0 Basics 7 January 3rd, 2007 02:10 PM
Question about Class Inheritance forkhead Pro VB.NET 2002/2003 0 March 21st, 2005 03:37 PM





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