tai*_*lec 1 c static objective-c ios objective-c-blocks
我在这个博客上发现了这个代码http://themainthread.com/blog/2014/02/building-a-universal-app.html
static void initSimpleView(SimpleView *self) {
// Configure default properties of your view and initialize any subviews
self.backgroundColor = [UIColor clearColor];
self.imageView = ({
UIImageView *imageView = [[UIImageView alloc] init];
imageView.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:imageView];
imageView;
});
self.label = ({
UILabel *label = [[UILabel alloc] init];
label.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:label];
label;
});
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
initSimpleView(self);
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
它是如何工作的?是什么意思static void initWithSimpleView(SimpleView *self)?为什么imageView和label在某种块的初始化?