• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Confused with block completionHandler
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Confused with block completionHandler


  • Subject: Re: Confused with block completionHandler
  • From: Brad Stone <email@hidden>
  • Date: Wed, 24 Aug 2011 21:07:42 -0400

All these answers are great.   Thanks

On Aug 24, 2011, at 9:01 PM, Graham Cox wrote:

>
> On 25/08/2011, at 10:46 AM, Brad Stone wrote:
>
>> I need to call this method manually but I'm confused how to format the completionHandler.  I don't understand what I'm reading.  Can anyone give me an example of how to define the completionHandler or point me to some documentation?
>>
>> [self saveToURL:[self fileURL] ofType:@"myDocType" forSaveOperation:NSAutosaveInPlaceOperation completionHandler:^(I'm confused!!!)];
>>
>> This is the method definition
>> - (void)saveToURL:(NSURL *)url ofType:(NSString *)typeName forSaveOperation:(NSSaveOperationType)saveOperation completionHandler:(void (^)(NSError *errorOrNil))completionHandler
>>
>> I've used blocks before like below but I don't understand the syntax above and I couldn't find an example on the internet or the documentation.  Any help would be appreciated.
>> [openPanel beginSheetModalForWindow:[NSApp keyWindow] completionHandler:^(NSInteger theResult) {
>> if (theResult) {
>>      // some code here
>> }
>
>
> Separate the block definition from the calling method to make it clearer:
>
>
> void (^completionHandler)(NSError*) = ^(NSError* error)
> {
>   // here, write the code that makes up the body of the completion handler
>
>
> }
>
> [self saveToURL:[self fileURL] ofType:@"myDoc" forSaveOperation:saveOp completionHandler:completionHandler];
>
>
> Here we just named the block 'completionHandler', but it could be anything, such as 'fred' - it's just a variable identifier.
>
>
>
> --Graham
>
>

_______________________________________________

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

References: 
 >Confused with block completionHandler (From: Brad Stone <email@hidden>)
 >Re: Confused with block completionHandler (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: Confused with block completionHandler
  • Next by Date: Re: Odd error logged when coming back from 'Browse All Versions'
  • Previous by thread: Re: Confused with block completionHandler
  • Next by thread: NSInvocationOperations mysteriously whacked out of NSOperationQueue
  • Index(es):
    • Date
    • Thread