Re: how to slim down view controllers?
Re: how to slim down view controllers?
- Subject: Re: how to slim down view controllers?
- From: Alex Zavatone <email@hidden>
- Date: Wed, 01 Apr 2015 10:22:10 -0400
There was a great article on this just this on objc.io a while ago.
Certainly worth a few reads before it sinks in.
I'm a big fan of not lumping everything together in one class, but moving certain responsibilities in to other classes and moving the appropriate code there.
What's odd to me is that Apple preaches MVC, but then when we have the view controller class, all to often the delegate is lumped into the same class, fostering code bloat and sorta going against compartmentalization of tasks (at least in my book it seems strange).
Here's the link to the article I'm thinking about.
http://www.objc.io/issue-1/lighter-view-controllers.html
Hope this helps. Cheers,
Alex Zavatone
On Apr 1, 2015, at 8:59 AM, Juan Felipe Alvarez Saldarriaga wrote:
> Hi,
>
> How you guys slim down your view controllers?, sometimes you end up implementing a lot of protocols in your view controller, so there’s a lot of code inside the controller itself. Reading about how to slim down view controllers in iOS I found that a common way is to move DataSources (http://www.objc.io/issue-1/lighter-view-controllers.html) to other class, but what about other delegates?, or if you create views by code?. First, I think about move each delegate to a NSObject class, so I try this:
>
> self.locationManager.delegate = [[FRRYPetDescriptionViewControllerLocationDelegate alloc] init];
>
> Then I ask in IRC and somebody suggest categories, so this is what I got so far:
>
> // FRRYPetDescriptionViewController.h
> @interface FRRYPetDescriptionViewController : UIViewController
>
> @property (nonatomic) CLLocationManager *locationManager;
>
> @property (nonatomic) TPKeyboardAvoidingScrollView *scrollView;
> @property (nonatomic) UIView *contentView;
>
> @end
>
> // FRRYPetDescriptionViewController+Protocols.h
> @interface FRRYPetDescriptionViewController (Protocols) <UITextViewDelegate, UIActionSheetDelegate, MFMailComposeViewControllerDelegate, UIGestureRecognizerDelegate, MKMapViewDelegate, UIViewControllerTransitioningDelegate, CLLocationManagerDelegate>
>
> @end
>
> // FRRYPetDescriptionViewController+UIAdditions.h
> @interface FRRYPetDescriptionViewController (UIAdditions)
>
> - (void)createScrollView;
> - (void)createContentView;
>
> @end
>
> // FRRYPetDescriptionViewController+Callbacks.h
> @interface FRRYPetDescriptionViewController (Callbacks)
>
> @end
>
> // FRRYPetDescriptionViewController+LocationAdditions.h
> @interface FRRYPetDescriptionViewController (LocationAdditions)
>
> @end
>
> This makes me think, what about “private” methods?, do I need to declare all properties in the view controller header file?. What you guys think about this approach or there’s some common pattern to follow to not end with a fat controller?.
>
> Thank you.
>
> --
> Juan Felipe Alvarez Saldarriaga
> http://juan.im
> Twitter: @nebiros
> Google Talk: email@hidden
> Skype: jfasaldarriaga
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden