Hi all,

I'm beginning a new application targeting Snow Leopard only. So I want to use 
the new tools (blocks) and garbage collection (GC). It will be my first 
application using GC.

I read some sites on GC and blocks. In the blog of Mike Ash I found some very 
interesting propositions. My question concerns his code for using block with 
sheets 
(http://www.mikeash.com/?page=pyblog/friday-qa-2009-08-14-practical-blocks.html).
 Is this code works in GC ?

@implementation NSApplication (SheetAdditions)

- (void)beginSheet: (NSWindow *)sheet modalForWindow:(NSWindow *)docWindow 
didEndBlock: (void (^)(NSInteger returnCode))block
{

[self beginSheet: sheet
        modalForWindow: docWindow
        modalDelegate: self
        didEndSelector: @selector(my_blockSheetDidEnd:returnCode:contextInfo:)
        contextInfo: [block copy]];
}

- (void)my_blockSheetDidEnd: (NSWindow *)sheet returnCode: 
(NSInteger)returnCode contextInfo: (void *)contextInfo  
{
void (^block)(NSInteger returnCode) = contextInfo;
block(returnCode);
[block release];
}

@end

I think, I have to replace [block copy] by CFRetain([block copy])
and [block release] by CFRelease(block).

Frédéric

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to