Re: Correct way to use contextInfo with ARC
Re: Correct way to use contextInfo with ARC
- Subject: Re: Correct way to use contextInfo with ARC
- From: Charles Srstka <email@hidden>
- Date: Thu, 04 Aug 2011 06:36:02 -0500
On Aug 3, 2011, at 8:38 PM, Kevin Bracey wrote:
> Hi All,
>
> A case of me not grasping C or/and ARC;-)
> I'm trying to pass the NSMutableArray across the void to the didEndSelector so I can access it if the user clicks ok.
>
> /snippits
>
> NSMutableArray *someInfo = [NSArray arrayWithObjects:@"made" , @"it", @"across",. nil];
>
> [holdAlert beginSheetModalForWindow:[self window] modalDelegate:self didEndSelector:@selector( alertDidEnd:returnCode:contextInfo: ) contextInfo:?how to send someInfo?];
>
>
> -(void)alertDidEnd:(NSAlert *)alert returnCode:(int)returnCode contextInfo:(void *)contextInfo
> {
> // not happy maybe use a sheet and block
> NSMutableArray *holdArray = ?contextInfo?;
>
> what magic do I use to pass it in and get it out;-)
Well, I can’t test this directly, since I haven’t been able to play with ARC yet due to Apple not having graced us lowly second-class-citizen Mac developers with the Xcode 4.2 beta, but according to the docs, you should be able to do this by casting the array to (__bridge_retained void *) when you give it to beginSheetModalForWindow:modalDelegate:didEndSelector:contextInfo:, and then casting it to (__bridge_transfer NSMutableArray *) in your alertDidEnd:returnCode:contextInfo: method.
Here’s the documentation page I’m referring to:
http://clang.llvm.org/docs/AutomaticReferenceCounting.html#objects.operands.casts
Charles_______________________________________________
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