Missing publicly accessible protocol/class for NSBlock.

Originator:satsumac
Number:rdar://10141831 Date Originated:2011/09/17
Status: Resolved:
Product:Mac OS X SDK Product Version:10.7
Classification:Enhancement Reproducible:n/a
 
Currently there appears to be no secure way to check blocks for validity, other than
    [block isKindOfClass:NSClassFromString(@"NSBlock")].

Further more the lack of a public protocol/class makes it hard (if not impossible) to safely accept a block as a method argument. You have to check at runtime using said (hacky-ish) method call (see above).

If exposing NSBlock to the public is a no-go for Apple (for reasony of internal implementation, or whatever), then please at least provide a public tagging protocol for blocks!

This way one could exchange
    [block isKindOfClass:NSClassFromString(@"NSBlock")].
for a much safer
    [block conformsToProtocol:@protocol(NSBlock)].

One could also have it throw compile time errors when using blocks as arguments.

    @protocol NSBlock
    //empty method list
    @end

    @interface NSBlock <NSBlock> {…}
    //existing private interface
    @end

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!