开发者

iOS 4 - Using blocks as a member of a class

开发者 https://www.devze.com 2023-01-28 00:57 出处:网络
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:

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 other typedef 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号