I was hoping someone could help me understand the syntax of blocks when used as members of a c开发者_开发百科lass. I have some code that's actually working just fine:
@class Structure;
typedef void (^StructureDeleteCallback)(Structure *);
@interface StructureListDelegate : NRFCTableDelegate
{
StructureDeleteCallback _structureDeleteCallback;
}
@property (nonatomic, copy) StructureDeleteCallback structureDeleteCallback;
@end
This works, but I would like to understand the syntax of the typedef
statement; and whether or not it's actually required to use typedef.
What I've read says that using typedef
in this situation is recommended because it makes the code a lot clearer; but I've been unable to get it to compile at all when trying to do this without typedef
. My understanding of typedef was that the syntax was basically:
typedef [actual type] [new name for type];
Such as:
typedef double CLLocationDegrees;
But the syntax of my typedef
statement doesn't match this. So my questions are:
- How can the syntax of my
typedef
statement be so different from othertypedef
statements / what does the syntax I'm using actually mean to the compiler? - Is it possible to
have a block as a member of a class
without using
typedef
?
I myself have asked a question along the lines of yours here: Block references as instance vars in Objective-C
See my answers here and here.
精彩评论