【发布时间】:2018-04-09 23:56:27
【问题描述】:
我正在从一个 Objective-C 类中调用一个函数。我将一个数组从我的 Swift 类传递到一个 Objective-C 函数中。
这是我的 Swift 代码
var videosAutoCompletion:[String] = []
completeSearch.autocompleteSegesstions(searchText, self.tableView, self.videosAutoCompletion)
Objective-C 函数
-(void)autocompleteSegesstions : (NSString *)searchWish :(UITableView*)table :(NSArray*)stringArray
在 Objective-C 函数内部我有一个块
dispatch_sync(dispatch_get_main_queue(), ^{
self.ParsingArray = [[NSMutableArray alloc]init]; //array that contains the objects.
for (int i=0; i != [jsonObject count]; i++) {
for (int j=0; j != 1; j++) {
//NSLog(@"%@", [[jsonObject objectAtIndex:i] objectAtIndex:j]);
[self.ParsingArray addObject:[[jsonObject objectAtIndex:i] objectAtIndex:j]];
//Parse the JSON here...
//NSLog(@"Parsing Array - %@",self.ParsingArray);
stringArray = [self.ParsingArray copy];
[table reloadData];
}
}
});
以下行出现此错误。
变量不可赋值(缺少 __block 类型说明符) 在行
stringArray = [self.ParsingArray copy];
【问题讨论】:
-
至少有两个 StackOverflow 问题可以解决此错误。它与 Swift 无关。它与使用“块”(Swift 中“闭包”的 Objective-C 名称)有关。 Assign a variable inside a Block to a variable outside a Block 和 “variable is not assignable (missing __block type specifier)” error when using a variable from method declaration in method block
标签: objective-c swift nsarray block