Objective C - using typedef struct in header file

I am trying to create a LinkedList in Objective C.

In the .h file, I'm trying to create a Node using the code:

@interface AALinkedList : NSObject
{
    typedef struct Node
    {
        int data;
        struct Node *next;
    } Node;
}

It gives me an error saying Type name does not allow storage class to be specified

What does it mean? and how to fix it?

+3
source share
2 answers
typedef struct Node {
    int data;
    Node *next;
} Node;

@interface AALinkedList : NSObject
{
    Node node;
    // or Node *node;
}
+4
source

You cannot declare typedef in a .h file. Declare it in .m. That should make you go. Sign the method on .h

You can create a simple LinkedList class like this.

@interface LinkedNode : NSObject 
  @property (nonatomic, strong) id nextNode;
@end
then you use it as you would expect:

id currentNode = myFirstNode;
do {
  [currentNode someMessage];
}
while(currentNode = currentNode.nextNode);
0
source

All Articles