如何更改块中的int值?

如何在块中更改int值,我有这样的:

__block long long size = -1; ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset) { ALAssetRepresentation * rep = [myasset defaultRepresentation]; size = [rep size]; //here showed normal value NSLog(@"needed size : %lld",size); }; ALAssetsLibrary* assetslibrary = [[[ALAssetsLibrary alloc] init] autorelease]; [assetslibrary assetForURL:self.tmpVideoURL resultBlock:resultblock failureBlock:nil]; //but here remaind -1 NSLog(@"out block value : %lld",size); 

问题在于,在assetForURL:...方法完成它的工作之后,它会在asynchronous执行之后的assetForURL:...时间发送该块。 这很可能在后台线程或队列中,允许方法本身在工作继续时立即返回。

所以方法assetForURL:... 你的resultBlock运行之前返回,这意味着在你到达第二个NSLog时值还没有被改变。 一切工作正常; 你只是检查价值太早。