• 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: Block error
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Block error


  • Subject: Re: Block error
  • From: Rick Mann <email@hidden>
  • Date: Fri, 15 Jul 2011 16:38:01 -0700

On Jul 15, 2011, at 16:21 , Jens Alfke wrote:

>
> On Jul 15, 2011, at 2:42 PM, Rick Mann wrote:
>
>> void
>> bar()
>> {
>>   (id) ^(id inParam1)
>>   {
>>       if ([inParam1 isEqual: @"baz"])
>>       {
>>           Foo* foo = [[Foo alloc] init];
>>           return foo;
>>       }
>>
>>       return nil;		//  Error here
>>   };
>> }
>
> Is this just a test to narrow down the error? Because this code doesn’t actually do anything — it just declares a block literal, casts it to type ‘id’, and ignores the result.

Yes, of course. It's just a simple example.

>
> I’m not sure how you explicitly specify the return type of a block, since usually it’s inferred for you by the compiler. You could try assigning the block to a variable of the type you want:

Sorry, the cast is left over from the real code I took this from. I do, in fact, assign the block to a variable of a type with return type id. It fails in the same way as my example, however.

>
> id myblock = ^(id inParam1) { … };
>
> The compiler will then infer that the return type of the block is ‘id’.

Not quite. I just read the docs more closely. The compiler infers the return type of the block fro the return statement. However, if you have multiple return statements, as I do, then they must match. I guess that's fine, except I feel like nil should always work.

--
Rick


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Block error
      • From: Scott Ribe <email@hidden>
    • Re: Block error
      • From: Eeyore <email@hidden>
References: 
 >Block error (From: Rick Mann <email@hidden>)
 >Re: Block error (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: Block error
  • Next by Date: Re: Block error
  • Previous by thread: Re: Block error
  • Next by thread: Re: Block error
  • Index(es):
    • Date
    • Thread