I am having this in MyClass.h file:
#import <UIKit/UIKit.h>
IB_DESIGNABLE
@interface MyClass : UIView
@end
and this is the code from the .m file:
-(void)awakeFromNib{
[super awakeFromNib];
NSLog(@"This works %lud",(unsigned long)self.max);
}
-(instancetype)initWithCoder:(NSCoder *)aDecoder{
if ((self = [super initWithCoder:aDecoder])){
NSLog(@"This doesn't work %lud",(unsigned long)self.max);
}
return self;
}
In awakeFromNib method, I get a correct value set in IB. In initWithCoder: I get this value equal to zero.
What is the appropriate time to check for a value, set in IB, for this property?
This is how I have defined a property in .m file:
@interface MyClass()
@property (nonatomic) IBInspectable NSUInteger max;
@end
You seem to have answered your own question: awakeFromNib
instead of initWithCoder:
. awakeFromNib
is later, and by that time, the runtime attributes have been set.
In real life, of course, you probably wouldn't care about this value until we get to viewDidLoad
, which is considerably later than both.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With