0

I have class like the following

@interface Node : NSObject {

NSString* description;
NSString* ae;
NSString* ip;
NSString*  port;
}

@property ( nonatomic , retain ) NSString* description;
@property ( nonatomic , retain ) NSString* ae;
@property ( nonatomic , retain ) NSString* ip;
@property ( nonatomic , retain ) NSString* port;

@end

#import "Node.h"

@implementation Node

@synthesize description,ae,ip,port;

@end

I want to create nsmutablearray of it So I do the following

NSMutableArray* nodesArray ;
nodesArray = [[NSMutableArray alloc] init];

Node * insertedNode =[[Node alloc]init] ;
insertedNode.description =@"test";
insertedNode.ae =@"test" ;
insertedNode.ip =@"test";
insertedNode.port =@"test";

[nodesArray addObject: insertedNode] ;

[insertedNode release];

then I print the count using

NSLog(@"%d",[nodesArray count] ) ;  

but it always always return 0

any suggestion to solve that

Best regards

9
  • Please fix your indentation. Please fix your title to describe the actual problem you're actually having. Commented Jun 2, 2011 at 11:37
  • @S.Lott I couldn't stand it any longer. Fixed. Commented Jun 2, 2011 at 11:37
  • 1
    @Abizern: That doesn't help @AMH learn how to write a good question, does it? Commented Jun 2, 2011 at 11:38
  • my problem is that I want to create nsmutablearray of class object but no insertion done Commented Jun 2, 2011 at 11:40
  • 1
    @AMH: Change the NSLog to NSLog(@"%@", nodesArray) and tell us what you get. Commented Jun 2, 2011 at 12:41

1 Answer 1

1

Perhaps NodesArray is failing to initialize? You could try testing to see if it is nil after you initialize it. (at [[NSMutableArray alloc] init])

Adding an object to a nil NSMutableArray * would fail silently, and [nil count] will always return zero.

(No idea why it would fail to initialize, but I can't imagine anything else causing the behavior you're describing.)

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

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.