Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 4 - Using blocks as a member of a class

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 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?
like image 711
GendoIkari Avatar asked Dec 01 '10 15:12

GendoIkari


1 Answers

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.

like image 128
Jacob Relkin Avatar answered Oct 04 '22 16:10

Jacob Relkin