Objective c 为什么我的数组计数方法在添加元素后返回零?

Objective c 为什么我的数组计数方法在添加元素后返回零?,objective-c,Objective C,我有如下的课程 @interface Node : NSObject { NSString* description; NSString* ae; NSString* ip; NSString* port; } @property ( nonatomic , retain ) NSString* description; @property ( nonatomic , retain ) NSString* ae; @property ( nonatomic , retain ) NSStr

我有如下的课程

@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
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];
我想创建它的nsmutablearray,所以我执行以下操作

@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
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];
然后我使用

NSLog(@"%d",[nodesArray count] ) ;  
但它总是返回0

有没有解决这个问题的建议


向您致意

也许
节点阵列
无法初始化?您可以在初始化后尝试测试它是否为
nil
。(位于
[[NSMutableArray alloc]init]

将对象添加到nil
NSMutableArray*
将以静默方式失败,
[nil count]
将始终返回零


(不知道为什么它无法初始化,但我无法想象还有其他原因导致您描述的行为。)

请修复您的缩进。请修改您的标题,以描述您实际遇到的实际问题。@S.Lott我再也受不了了。已修复。@Abizern:这无助于@AMH学习如何编写一个好问题,是吗?我的问题是我想创建类对象的nsmutablearray,但不想插入done@AMH:将NSLog更改为
NSLog(@“%@”,nodesArray)
并告诉我们您得到了什么。