如何更改块中的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
时值还没有被改变。 一切工作正常; 你只是检查价值太早。
- 在Swift中使用正则expression式进行简单search时,如何避免由于searchstring中的特殊字符造成的错误?
- 在Google地图中点击标记时显示信息窗口在实现mapView时执行iOS sdk:didTapMarker:实现了delegate方法
- 你能用IOS7.1 SDK来使用XCode6.3吗?
- CVOpenGLESTexture方法types的官方文档在哪里?
- Firebaseasynchronousfunction,后台队列中有什么,什么不是
- UISearchController禁用取消UIBarButtonItem
- 如果从故事板创buildbutton,则更改子类中的UIButtontypes
- 试图用GCD创build一个精确的计时器
- 如何创build具有全屏图像ios的自定义UIImagePickerController