Skip to content

Instantly share code, notes, and snippets.

@JimRoepcke
Created January 15, 2013 06:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JimRoepcke/4536602 to your computer and use it in GitHub Desktop.
Save JimRoepcke/4536602 to your computer and use it in GitHub Desktop.
Putting a category on model classes to specialize UI/layout code for each model type
// In MyViewController.m
@interface BaseModelClass (MyViewControllerLayout)
// If your model classes don't have a common superclass, put
// this category on NSObject instead
- (void)layoutForMyViewController:(MyViewController *)controller;
@end
@implementation ModelA (MyViewControllerLayout)
- (void)layoutForMyViewController:(MyViewController *)controller
{
// layout ModelA object for MyViewController
}
@end
@implementation ModelB (MyViewControllerLayout)
- (void)layoutForMyViewController:(MyViewController *)controller
{
// layout ModelB object for MyViewController
}
@end
@implementation ModelC (MyViewControllerLayout)
- (void)layoutForMyViewController:(MyViewController *)controller
{
// layout ModelC object for MyViewController
}
@end
@implementation MyViewController
- (void)someLayoutMethod
{
for (BaseModelClass *modelObject in self.modelObjects)
{
[modelObject layoutForMyViewController:self];
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment