我想知道如何正確地執(zhí)行以下操作:我有一個(gè)方法,即返回NSData對象。它得到了NSData對象的UIDocument..這個(gè)NSData對象可以變大,因此我希望確保在響應(yīng)啟動(dòng)之前完全加載它。因此,我想從塊本身中返回方法的值。所以就像這樣:- (NSData*)getMyData {
MyUIDocument *doc = [[MyUIDocument alloc] initWithFileURL:fileURL];
[doc openWithCompletionHandler:^(BOOL success) {
if (success) {
return doc.myResponseData; // this is to be the return for the method not the block
}
}];}這會(huì)導(dǎo)致錯(cuò)誤,因?yàn)閞eturn顯然是指block氏return.我如何才能做到這一點(diǎn),而不必讓線程阻塞等待/同時(shí)循環(huán)呢?謝謝。
從內(nèi)部塊返回方法對象
慕的地6264312
2019-07-13 16:01:38