self.tableView = ({
CGRect frame = CGRectMake(0.f, 0.f, kBPNavigationBarClockInOutAssociatesTableViewWidth,
kBPNavigationBarClockInOutAssociatesTableViewHeight);
UITableView * tableView =
[[UITableView alloc] initWithFrame:frame style:UITableViewStylePlain];
tableView.autoresizingMask = (UIViewAutoresizingFlexibleTopMargin
|UIViewAutoresizingFlexibleBottomMargin
|UIViewAutoresizingFlexibleWidth);
tableView.delegate = self;
tableView.dataSource = self;
[tableView setOpaque:NO];
[tableView setScrollEnabled:YES];
[tableView setBounces:YES];
[tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
[tableView setBackgroundView:nil];
[tableView setBackgroundColor:[UIColor clearColor]];
tableView;
});
- 첫번째 질문 :
({})가 동기 모드로 래핑 된 코드를 실행에있는 tableView의 객체를 반환 할 수 재미있다 그 내용의 끝.
나는 그냥보고되지하지만 이유가 여기에 블록 가정 같은 :
UITableView * (^testBlock) (void) = ^{ // Codes here... return tableView;};
UITableView *myTableView = testBlock();
- 두번째 질문
({}) 비동기 모드에 있지 않을 때 Xcode에서 코드를 테스트하지만 내 경험에 따르면 블록은 항상 (비주류 슈퍼 주니어 질문은 항상 비동기 모드로 실행되는 블록입니까?) 비동기 모드로 실행됩니다. 그럼 왜 여기 없습니까?
- 세번째 질문
내가 반환 객체 블록 구문을 구글 때, 나는 그런 BOOL 더블, 충분히 운이 모든 블록을 반환 프리미티브 값은 객체를 반환을 찾을 것을 발견 . 블록이 프리미티브 값만 반환 할 수 있다는 것은 사실입니까?
reviese는 :
NSString *(^print_block)() = ^{
return @"this block worked!";
};
NSLog(@"%@", print_block());
그래서 내가 블록도 개체 형식을 반환 할 수 있다고 생각 :
나는 Why doesn't this rudimentary Objective C-block code work?에서이 조각을 찾을 수 있습니다.
감사합니다.
http://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html#Statement-Exprs (블록이 아닙니다)를 참조하십시오. – par
예, 블록입니다. https://developer.apple.com/library/ios/documentation/cocoa/conceptual/programmingwithobjectivec/WorkingwithBlocks/WorkingwithBlocks.html 그러나 비동기를 원하면 Grand Central Dispatch를 사용하여 Dispatch Queues를 사용해야합니다 (문서 링크의 맨 아래) – Horst
@Horst - 블록은 캐럿을 사용합니다. '^ {'. 그가'({})에 대해 묻는 구문은 전혀 다른 것입니다. 게시 한 링크를 참조하십시오. – par