我正在查看REMenu lib代码,并看到vars被声明为wiht ({...}); ..看起来像'封闭'到懒惰的评估代码..我不知道..有人可以解释一下吗?
self.menuWrapperView = ({
UIView *view = [[UIView alloc] init];
view.autoresizingMask = UIViewAutoresizingFlexibleWidth;
if (!self.liveBlur || !REUIKitIsFlatMode()) {
view.layer.shadowColor = self.shadowColor.CGColor;
view.layer.shadowOffset = self.shadowOffset;
view.layer.shadowOpacity = self.shadowOpacity;
view.layer.shadowRadius = self.shadowRadius;
view.layer.shouldRasterize = YES;
view.layer.rasterizationScale = [UIScreen mainScreen].scale;
}
view;
});
self.toolbar = ({
UIToolbar *toolbar = [[UIToolbar alloc] init];
toolbar.barStyle = self.liveBlurBackgroundStyle;
if ([toolbar respondsToSelector:@selector(setBarTintColor:)])
[toolbar performSelector:@selector(setBarTintColor:) withObject:self.liveBlurTintColor];
toolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
toolbar;
});
Run Code Online (Sandbox Code Playgroud) 我正在仔细阅读第三方RESideMenu框架的代码,并注意到一些奇怪的语法似乎工作正常.这是令人困惑的一点:
self.tableView = ({
UITableView *tableView = [[UITableView alloc] initWithFrame:frame style:UITableViewStylePlain];
tableView.autoresizingMask = mask;
tableView.delegate = self;
tableView.dataSource = self;
tableView.opaque = NO;
tableView.backgroundColor = [UIColor clearColor];
tableView.backgroundView = nil;
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
tableView.bounces = NO;
tableView.scrollsToTop = NO;
tableView;
});
Run Code Online (Sandbox Code Playgroud)
这种语法如何工作?我怀疑它与C级块确定有关,但我以前从未见过这个.我也认为它可能是Objc-2.0文字的新功能,但我不认为这是真的.
所以我想我的问题是这是如何工作/使这项工作的原因?
在Objective-C中是否可以创建内联块并使用其返回类型?例如,我可以创建一个返回a的块,BOOL使其内联,并使用其返回类型进行赋值.
BOOL b = <inline block that returns BOOL> { // unsure of the syntax / legality of this
return YES; // will be more logic in here, that is why I want to use a block.
};
Run Code Online (Sandbox Code Playgroud)
我遇到块语法问题,不确定是否可以内联创建块.我检查了以下资源但没有用.
谢谢您的时间和耐心,如果这不可能或非常容易.