I'm new to OOP, having been a procedural programmer for many years. I'm learning iOS development in Objective-C and could use some clarity on when and how objects and properties are used.

Say I have a view controller, MyViewController. Within that is a UIView, MyView, with a property, viewProperty.

How do I reference viewProperty from within MyViewController? My hunch is that I need to instantiate an instance of MyView, say:

MyView *instanceView;

and then reference instanceView.viewProperty. But without having instantiated a MyView at all, a MyView view shows up in MyViewController when I run the iPhone Simulator. Is that because my XIB file implicitly instantiates an instance of MyView? If so, how do I reference that instance in code? If I have to instantiate a MyView instance within MyViewController, which method(s) should contain the declaration, and why?

I hope I explained my foggy perceptions adequately for someone to clear things up for me. Apologies if I'm not making sense, but I feel like if someone just connects the dots for me I'm almost there.

  • This belongs on SO. Specific question, not subjective. Commented Jul 18, 2011 at 18:37
  • @P.Brian: Programmers.SE is for conceptual, whiteboard-y questions; Stack Overflow is for implementation, issue-while-I'm-coding questions. Commented Jul 18, 2011 at 18:46
  • "How do I reference viewProperty from within MyViewController? " is asking for an implementation. He needs an implementation to solve the reference problem. The initial question and title are misleading and really a different topic. So, I suggest the OP either create two distinct questions (one for OO best practices and another for the reference problem) or consolidate this one into something on topic for one of the two sites. Commented Jul 18, 2011 at 18:49

1 Answer 1


How do I reference viewProperty from within MyViewController?

You shouldn't. In the OOP pattern, your controller object should send a message to the view object if it needs to update some property information in the view or get some state information back.

A XIB instantiates objects when it is loaded, you can hook them up to code in Interface Builder if you need to reference those objects from code. Or you can create objects programmatically when your controller initialization methods are called and not use a .xib file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.