【发布时间】:2018-01-27 06:46:13
【问题描述】:
这里是目标 c 的新手...我正在尝试初始化 2 个字符串并稍后设置它们,但我收到了 r1 和 r2 的此错误:
the variable is not assignable (missing _block type specifier)
我的代码如下:
NSMutableString *r1 = [NSMutableString stringWithFormat:@"None"];
NSMutableString *r2 = [NSMutableString stringWithFormat:@"None"];
NSURLRequest *request = [client URLRequestWithMethod:@"GET" URL:statusesShowEndpoint parameters:params error:&clientError];
if (request) {
[client sendTwitterRequest:request completion:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
if (data) {
// handle the response data e.g.
NSError *jsonError;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError];
NSLog(@"ok!");
for(NSString *key in [json allKeys]) {
NSLog(@"%@",key);
}
r1 = json[@"statuses"][0][@"text"];
r2 = json[@"statuses"][1][@"text"];
我很困惑这是否是设置字符串的正确方法...... 就像我想做的就是初始化一个字符串并稍后设置它。
【问题讨论】:
-
您的错误表明您包含的代码没有包含足够的上下文供人们验证您的问题。这两个任务究竟在哪里?编辑您的问题以提供更多背景信息,以便人们可以更好地帮助您。
-
不清楚,缺少信息,但如果我在这里猜测,我会说你有一个带有块的
NSURLSession的异步调用,你想检索一些值到r1和r2,它们是在块之前声明的,因此您需要改为__block NSString *r1。见那里:stackoverflow.com/questions/7080927/… 另外,你定义它的方式是可变的,但我强烈认为json[@"statuses"][0][@"text"]并不是真正可变的,是NSString而不是NSMutableString。
标签: objective-c xcode nsstring