r/iOSProgramming • • 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.aspx
1 Upvotes

11 comments sorted by

View all comments

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?

3

u/sobri909 Jun 02 '14

Interface holds instance variables;

There's nothing wrong with using ivars if you have no need for setters and getters. They're not deprecated, and have many perfectly valid uses.

No storyboarding;

Storyboards have been fairly universally panned as a tool for apps of any reasonable size. They're a great idea, but they don't scale, and the tools provided are still weak and will ultimately slow you down more than they help you out.

UIViewController initialisation with simple init;

Nothing wrong with this. If you can't call init on a class and get something usable, it's not built right.

Label uses autoresizing mask instead of constraints;

In our projects we still don't use Auto Layout. It offers us nothing we haven't already got, and comes with a large amount of baggage. It's over engineered, and only suitable for extreme cases. Eventually everyone's going to realise this, and drop it like it's XML in a JSON world.

2

u/[deleted] Jun 02 '14

They're not deprecated, and have many perfectly valid uses.

They do have a valid use if they are not in public interface. In OP's case - ivars are bleeding implementation details which breaks OOP

My point about storyboarding is that it provides a mechanism of passing data between view controllers in any direction. And in case of "going backwards" - through any amount of segues (unwinding). Thus OP reinvents the wheel. And poorly for that matter as well, since UINavigationControllerDelegate provides delegate methods to implement for tracking pushing and popping of its child view controllers;

I will a agree on you with Auto-Layout over-engineering (still dropping it like XML would be bold claim), however op at least could use xib to create UILabel instead of making everything in code. After all - he did use init method which should call the designated initWithNibName:bundle: initialiser.

2

u/IGDev Jun 02 '14 edited Jun 02 '14

Just to clarify if you didn't look at the source, the ivars are not declared in a public facing interface.

The use of UINavigationControllerDelegate vs rolling your own delegate protocol depend on the design of the app's screens and the flow of data. For example, if the SecondViewController shown in the blog post was a controller that will be instanced and pushed from multiple view controllers, it's ideal to roll your own delegate protocol.

1

u/[deleted] Jun 03 '14

I apologise for my overlook of details.

1

u/sobri909 Jun 03 '14

Yeah I'm being overly hopeful about Auto Layout getting eventually dropped. I suspect it's here to stay, which disappoints me greatly.

2

u/cosmoismyidol Jun 02 '14

True, it is quite outdated. That said..

UIViewController initialisation with simple init

Acceptable when using Nibs - the designated initializer is called by the default init with reasonable defaults.

Label uses autoresizing mask instead of constraints

Autoresizing masks are translated into constraints by iOS. Using them can simplify programatic constraint manipulation.

3

u/IGDev Jun 02 '14

The blog post is dated with 05/29/2014.

  • Interface holding instance variables is common, especially when you don't need to expose those publicly

  • Not everyone uses storyboarding

  • There's nothing wrong with initializing a view or view controller using a simple init

  • Not everyone uses constraints

-1

u/Deepmist Jun 02 '14

As long as we have iPad 1 users we will probably not use constraints. It's a minor programming convenience at the cost of a generation of hardware.