Amazon.com Widgets Chapter 8 @property/@synthesize question
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 19, 2013, 07:20:50 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
|-+  Old Stuff
| |-+  Answers to Exercises
| | |-+  Chapter 8
| | | |-+  Chapter 8 @property/@synthesize question
Pages: [1]   Go Down
Print
Author Topic: Chapter 8 @property/@synthesize question  (Read 433 times)
darkslayer13
Newbie
*
Posts: 4


Email




« on: May 02, 2011, 08:47:13 PM »

Hi - so I was going through chapter 8 thinking that I understood everything from before. Then I came across this code on pg 166:

@interface XYPoint: NSObject
{
      int x; int y;
}
@property int x, y;

-(void) setX: (int) xVal andY: (int) yVal;

@end



I thought when doing the @property and @synthesize statements, the setter and getter methods are created for you. So, why is the following statement part of the interface file, and not only the implementation file?

-(void) setX: (int) xVal andY: (int) yVal;

/////////////////////////////

Also, as a side question:

I couldnt really figure it out, but when do you use pointers like this:

(XYPoint *) origin

instead of this:

XYPoint *origin
Logged
skochan
Administrator
Hero Member
*****
Posts: 3103







« Reply #1 on: May 02, 2011, 10:40:30 PM »

First, setX:andY: is not a synthesized method; it is a convenience method that was added to allow you to set two properties with a single method call.  It's an arbitrary addition to the class.

Second, the Objective-C syntax for return values for methods and for arguments to methods requires the object type be enclosed in parentheses.  I don't know why that is, but it is.  Smiley

Cheers,

Steve
« Last Edit: May 03, 2011, 08:13:02 AM by skochan » Logged
darkslayer13
Newbie
*
Posts: 4


Email




« Reply #2 on: May 02, 2011, 10:43:42 PM »

Wow! Thanks for the quick response! I cant wait for the 3rd ed to come out! Already preordered!  Grin

Cheers,

~Zach
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.