Skip to content

Instantly share code, notes, and snippets.

@shineycode
Last active August 29, 2015 14:11
Show Gist options
  • Save shineycode/5cfa57e3b91636bef0ef to your computer and use it in GitHub Desktop.
Save shineycode/5cfa57e3b91636bef0ef to your computer and use it in GitHub Desktop.
// MyViewController inherts from UIViewController
@interface MyViewController()
// ---------QUESTIONS---------
// 1. Should you do this, only to avoid casting later when you need to access MyCustomView specific properties?
// 2. How does the compiler treat this property (and the backing ivar) that's re-declared at the inheriting class level?
// Does it shadow the version that exists at the UIViewController level?
// 3. Wouldn't this cause a leak?
@property (nonatomic, strong) MyCustomView *view;
@end
@implementation MyViewController
- (void)viewDidLoad {
self.view = [[MyCustomView alloc] initWith..]; // this is ok
self.view.button.titleLabel = @"some label" // button is automatically created in MyCustomView constructor
}
@end
// MyCustomView inherits from UIView
@interface MyCustomView : UIView
@property (nonatomic, weak) UIButton *button;
@property (nonatomic, weak) UILabel *label;
@end
@implementation MyCustomView
- (instancetype)init {
self = [super init];
if (self) {
_button = [[UIButton alloc] init.. ];
_label = [[UILabel alloc] init.. ];
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment