0

I want to add a structure to arrays. The following is my structure

struct Nodes {

NSInteger nodeGridNumber;
Boolean visited;
struct Nodes *nextNode;

};

Can any one with help with this. Thanks

2 Answers 2

1

Use :
Nodes *node = [Nodes alloc];
NSMutableArray *arr =[[NSMutableArray alloc]init];
[arr addObject:node];

Sign up to request clarification or add additional context in comments.

1 Comment

I am getting error at this line Nodes *node = [Nodes alloc]; say undefined symbols Nodes and node. I tried using type def typedef struct Nodes NodeStruct; and rewritten the code this way. NodeStruct *node;// = [NodeStruct alloc]; NSMutableArray *arr =[[NSMutableArray alloc]init]; [arr addObject:node]; Then I am getting the error in the last line sayingpassing argument of incompatable type.
0

My suggestion for you would be to use class instead of struct:

@interface Nodes : NSObject{

  NSInteger nodeGridNumber;
  Boolean visited;
  struct Nodes *nextNode;

};

Then you could add it to NSMutableArray. And of course, import class header file, where you need to use this class.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.