I tend to do everything with Interface Builder and IBOutlet, so that when I want to modify user interface I use to declare a variable in UIViewController, for example:
@property(nonatomic,retain) IBOutlet MyView *myView;
connect it trough Interface Builder and recall in my code using the outlet, then I can access all the other outlet in myView:
UILabel *label = myView.theLabel;
Considering that MyView is very often my main view, I could also do:
UILabel *label = (MyView*)self.view.theLabel;
the syntax is quite long, but this allow me to declare less variable in the .h file and (in my opinion) keep code cleaner, for example with a macro this could become:
#define MV (MyView*)self.view
UILabel *label = MV.theLabel;
which I found to be much more nice to read and maintain.
The point is that I would always do a casting, using iOS 5 what’s the cost in terms of performance ? Considering the UIKit is already a layer on top of something else is UIView object casting somewhat different or more expensive ?
Does the compiler do some kind of optimizations especially with the new arc compiler ?
thanks
Casting happens at compile time, and as such has absolutely no runtime cost.
Sidebar: This way of using defines still strikes me as a bit iffy, but hey, if it works for you…
Edit: The issue you are describing is a result of conflating the purposes of the classes in your code: MyView should not need to have any outlets to speak of; keeping track of all of that jazz is the job of the view controller.
In other words; you probably don’t want
self.view.label; but ratherself.relevantNameForTheLabel.