Advertisement
Guest User

Static initializers .m

a guest
May 29th, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #import "MyPointView.h"
  2.  
  3. @implementation MyPointView
  4.  
  5. +(instancetype)instanceFromNib
  6. {
  7.     MyPointView *view = [[[UINib nibWithNibName:@"MyPointView" bundle:nil] instantiateWithOwner:self options:nil] firstObject];
  8.    
  9.     return view;
  10. }
  11.  
  12. +(instancetype)instanceWithPoints:(NSArray*)points
  13. {
  14.     MyPointView *view = [self instanceFromNib];
  15.    
  16.     view.myPoints = points;
  17.    
  18.     return view;
  19. }
  20.  
  21. +(instancetype)instanceWithPoints:(NSArray*)points andName:(NSString*)name
  22. {
  23.     MyPointView *view = [self instanceFromNib];
  24.    
  25.     view.myPoints = points;
  26.     view.routeName = name;
  27.    
  28.     return view;
  29. }
  30.  
  31. -(void)setMyPoints:(NSArray *)myPoints
  32. {
  33.     //Do some custom procesing on the points array first, if you want. Notice how this only has to be done in one place.
  34.     _myPoints = myPoints;
  35. }
  36.  
  37. -(void)setRouteName:(NSString *)routeName
  38. {
  39.     //We'll lowercase this string before setting. Notice how this only has to be done in one place.
  40.     _routeName = [routeName uppercaseString];
  41. }
  42.  
  43. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement