开发者

Why does my array -count method return zero after adding an element?

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* i开发者_如何学Cp;
@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


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.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜