r/iOSProgramming • u/IGDev • Jun 02 '14
Passing Data Between View Controllers
http://www.infragistics.com/community/blogs/torrey-betts/archive/2014/05/29/passing-data-between-view-controllers-ios-obj-c.aspx2
u/eaz135 Jun 02 '14
You would generally be passing model objects around in an MVC setup. For eg if you had an IGArticle object and an IGArticleViewController you may have an init method - (id)initWithArticle:(IGArticle *)article. Simply exposing properties can make it a bit confusing on how to consume your controller. Are these properties required to be set? What happens if I don't set this property, will things break?
Having said that exposing readwrite properties is fine when their purpose and usage is documented in the interface and sensible defaults are set.
If multiple parties are interested in a particular object then registering to KVO to observe changes is a better option than slinging the values around various controllers as things change.
1
u/mantra Jun 02 '14
In general, I disagree with this most of the time - this should be an exceptional thing as best.
You SHOULD have a MVC and model design that trivially avoids this kind of thing - if you end up with this as rule, you've done something wrong in your fundamental design. Data needed in common between View Controllers should simply be coming from the same model (or Model Controller!) via the app controller overseeing the connections.
This is part of why I start the design process with data model first once I have user data and interactions defined.
1
u/[deleted] Jun 02 '14
How old is this blog post?
Interface holds instance variables;
No storyboarding;
UIViewController initialisation with simple
init;Label uses autoresizing mask instead of constraints;
Anything else i've missed?