Ios 将变量作为参数传递给块

Ios 将变量作为参数传递给块,ios,objective-c,Ios,Objective C,我在objective c中运行一个代码块,并将一个变量作为参数传递给它,该变量的值在块内发生变化。有没有办法做到这一点 __block int timestamp=0; [MyAPI queryName:timestamp withBlock:^(Data *data) { NSLog(@"%@", data); timestamp = data.timestamp; }]; 我无法使用上述代码实现这一点。不确定什么是正确的方法来完成这件事,或者以其他方式是否可行。谢谢。我假设qu

我在objective c中运行一个代码块,并将一个变量作为参数传递给它,该变量的值在块内发生变化。有没有办法做到这一点

__block int timestamp=0; 
[MyAPI queryName:timestamp withBlock:^(Data *data) {
  NSLog(@"%@", data);
  timestamp = data.timestamp;
}];

我无法使用上述代码实现这一点。不确定什么是正确的方法来完成这件事,或者以其他方式是否可行。谢谢。

我假设queryName:withBlock:是对您的服务器的呼叫?如果是这样,块外的时间戳将在稍后更新,并且下面的所有代码都会看到时间戳为0


解决方案是根据块调用中的时间戳执行。

我正在监听服务器上打开的套接字,试图构建一个instant messenger应用程序。我正在使用firebase api`[[[self.myRootRef queryOrderedByChild:@timestamp]queryStartingAtValue:[NSNumber numberwhithint:ts]]observeEventType:FEventTypeValue with block:^FDataSnapshot*snapshot{ts=snapshot.timestamp;}'我不知道我是否真的可以在块内执行。。