Re: Recursive call-back block
Re: Recursive call-back block
- Subject: Re: Recursive call-back block
- From: Fritz Anderson <email@hidden>
- Date: Tue, 10 Apr 2012 10:50:14 -0500
On 10 Apr 2012, at 9:13 AM, Mikkel Islay wrote:
> Hello,
>
> The (prototype) code below updates a number of objects of a NSManagedObject-sublass (Progenitor) from a remote host. As the number of objects to update is unknown I would like to use a call-back passed to the updater class invoked by startParserWithObjectId: completionBlock: to recursively call returnblock on the next progenitor-object, so serially, when the update-task has completed.
>
> However, the static analyser gives me the warning : "Variable 'returnblock' is uninitialized when captured by block". It is unclear to me how to interpret the message. Can anyone shed light on it?
>
> NSEnumerator __block *collectionEnum = [progenitors objectEnumerator];
> Progenitor *firstProgenitor = [collectionEnum nextObject];
>
> void (^returnblock)(Progenitor *) = ^(Progenitor *aProgenitor) {
> if (aProgenitor == nil) return;
> CellUpdater *aCellUpdater = [[CellUpdater alloc] init];
> [aCellUpdater setThisPersistentStoreCoordinator:thisPersistentStoreCoordinator];
>
> [aCellUpdater startParserWithObjectId:[aProgenitor objectID] completionBlock:^(NSManagedObjectID *anID) {
> [[NSNotificationCenter defaultCenter] postNotificationName:@"updateExistsForProgenitor" object:anID];
> returnblock([collectionEnum nextObject]);
> }];
> };
>
> returnblock(firstProgenitor);
The block literal [ ^(Progenitor *aProgenitor) { ... ] is created first. Then the address of the created block is assigned to returnblock. But returnedblock is referenced in the block, before the assignment to returnblock gives it a value.
— F
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden