iOS 4 - 使用块作为类的成员
我希望有人可以帮助我理解块用作类成员时的语法。我有一些代码实际上工作得很好:
@class Structure;
typedef void (^StructureDeleteCallback)(Structure *);
@interface StructureListDelegate : NRFCTableDelegate
{
StructureDeleteCallback _structureDeleteCallback;
}
@property (nonatomic, copy) StructureDeleteCallback structureDeleteCallback;
@end
这可以工作,但我想了解 typedef
语句的语法;以及是否确实需要使用 typedef。
我读到的内容表明,在这种情况下建议使用 typedef,因为它使代码更加清晰;但当我尝试在没有 typedef
的情况下执行此操作时,我根本无法编译它。我对 typedef 的理解是,语法基本上是:
typedef [actual type] [new name for type];
如:
typedef double CLLocationDegrees;
但我的 typedef
语句的语法与此不匹配。所以我的问题是:
- 我的
typedef
的语法如何 声明与其他声明如此不同typedef
语句/我使用的语法对编译器实际上意味着什么? - 是否可以 有一个块作为类的成员 不使用 typedef?
I was hoping someone could help me understand the syntax of blocks when used as members of a class. 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 usingtypedef
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我自己在这里问了一个与您类似的问题: 阻止引用为Objective-C 中的实例变量
查看我的回答这里和这里。
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.