IBOutlet on Field or Property?
I'm currently reading through Beginning iPhone Development: Exploring the iPhone SDK and noticed that they place the IBOutlet declaration on their fields and then add properties that don't have IBOutlet. Yet it most of the Apple samples, they put the IBOutlet on the property instead of the field. Is there any difference between the two or are they two means to the same end?
I'm not totally sure I understand what you're seeing/saying, but I suspect you're talking about the new "synthesize" stuff with the new Obj-C (I forget what the proper terminology is for it). Yes, they wind up being the same thing.
The point of the synthesis is to cut down on writing code because otherwise you have to write all the accessors yourself. Personally I'm not sure it helps all that much because I think that since you can do it two ways all over the place, it can make the code somewhat confusing, especially to newcomers.
The point of the synthesis is to cut down on writing code because otherwise you have to write all the accessors yourself. Personally I'm not sure it helps all that much because I think that since you can do it two ways all over the place, it can make the code somewhat confusing, especially to newcomers.
No, it's not the synthesize stuff. Basically I've seen two ways of declaring IBOutlets in classes. My book always writes it like this:
But all the stock templates and the Apple sample code moves the IBOutlet over to the property like this:
I'm just wondering if it matters which has the IBOutlet label on it or if they wind up doing the same thing.
Code:
@interface Something
{
IBOutlet UIButton *button;
}
@property (nonatomic, retain) UIButton *button;
@endBut all the stock templates and the Apple sample code moves the IBOutlet over to the property like this:
Code:
@interface Something
{
UIButton *button;
}
@property (nonatomic, retain) IBOutlet UIButton *button;
@endI'm just wondering if it matters which has the IBOutlet label on it or if they wind up doing the same thing.
Yeah, actually, that is the "synthesize" stuff I was talking about (again, sorry I don't have the proper terminology, which is no doubt causing confusion).
In the implementation file, those "properties" get synthesized into the same thing as how you'd write it by hand. The terminology is "property", but in reality, they're just instance variables. So: It doesn't matter which way you do it.
In the implementation file, those "properties" get synthesized into the same thing as how you'd write it by hand. The terminology is "property", but in reality, they're just instance variables. So: It doesn't matter which way you do it.
Ah ok. Thanks.
FYI: Apple recommends sticking it on the property. I read that in some dev doc that I can't seem to find at the moment.
Josh Wrote:FYI: Apple recommends sticking it on the property. I read that in some dev doc that I can't seem to find at the moment.
Hmm... I wonder why? Maybe it works better with the new IB or something? KVC/KVO should work the same either way, so I'm guessing it must be for the tools' benefit.
Nick Wrote:I'm currently reading through Beginning iPhone Development: Exploring the iPhone SDK and noticed that they place the IBOutlet declaration on their fields and then add properties that don't have IBOutlet. Yet it most of the Apple samples, they put the IBOutlet on the property instead of the field. Is there any difference between the two or are they two means to the same end?
offtopic: Just one question. I read on amazon that "Beginning iPhone Development: Exploring the iPhone SDK" is a paperback. Does it mean if I buy I will receive a PDF or something like that?
Thanks a lot.
"Paperback" means it doesn't have a hard cover (like thick cardboard), but instead uses a thick paper (like a card) for the covers. Hard cover books generally cost more. Most computer books I have are paperback. College textbooks are often hard covers.
AnotherJake Wrote:Hmm... I wonder why? Maybe it works better with the new IB or something? KVC/KVO should work the same either way, so I'm guessing it must be for the tools' benefit.
The 64-bit runtime can synthesize instance variables using property declarations. Presumably, "IBOutlet" is being moved to the property declarations to make it easier to delete those unneeded instance variable declarations someday.
riruilo Wrote:offtopic: Just one question. I read on amazon that "Beginning iPhone Development: Exploring the iPhone SDK" is a paperback. Does it mean if I buy I will receive a PDF or something like that?
Thanks a lot.
Actually you can buy the PDF separately, for $10.
http://www.apress.com/promo/tendollars/
It says you need to answer "a randomly generated question" which I assume means you need the book in hand when you register.
Nick Wrote:they place the IBOutlet declaration on their fields and then add properties that don't have IBOutlet. Yet it most of the Apple samples, they put the IBOutlet on the property instead of the field. Is there any difference between the two or are they two means to the same end?
Hi,
in Ye Olde Days, there were no properties, so one put the IBOutlet label on the ivars. Now that we have properties, you should put them on the property. That way, you can freely choose how to store the property's contents. Put it in an ivar, put it in an ivar with a different name, put several properties into the same internal ivar, put all ivars into a struct to avoid the fragile base class problem, have the New Runtime synthesize the ivars for you...
Cheers,
-- Uli
Welcome, Uli!!
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Create a dictionary property list programmatically | ulquiorra | 0 | 1,854 |
Jul 14, 2009 05:08 AM Last Post: ulquiorra |
|
| Save game state using Property list or Text File? | Graphic Ace | 2 | 3,223 |
Apr 6, 2009 03:48 AM Last Post: Graphic Ace |
|

