【发布时间】:2014-04-15 06:56:34
【问题描述】:
我正在用 C 语言创建一个链接列表,添加时出现错误(还有警告)。
这两个都写在下面。
我尝试了一些无济于事的事情......任何建议都会很棒。
[它是一个最大大小的链表!]
//in the tester
XCTAssertNotNil(testList.head.next);
抛出此错误
failed: ((testList.head.next) != nil) failed: throwing "-[__NSCFNumber next]: unrecognized selector sent to instance 0x8d75720"
这是添加方法
- (void)add:(NSObject *)node {
Node *newNode = [[Node alloc] init];
if (self.head)
newNode.next = self.head;
else
self.head = newNode;
self.num_nodes++;
}
NList *testList = [[NList alloc] initWithSize:2];
发出警告
不兼容的整数到指针的转换将“int”发送到“NSInteger *”类型的参数(又名“int *”)
这是构造函数
@property (nonatomic,readwrite) NSInteger size;
.....
- (id) initWithSize:(NSInteger *)size {
self = [super init];
if (self){
self.head = nil;
self.size = *size;
self.num_nodes = 0;
}
return self;
}
编辑
- (void)testAdd
{
NList *testList = [[NList alloc] initWithSize:2];
NSObject *testNodeOne = @1;
[testList add:(testNodeOne)];
XCTAssertNotNil(testList.head);
NSObject *testNodeTwo = @3;
[testList add:testNodeTwo];
XCTAssertNotNil(testList.head);
XCTAssertNotNil(testList.head.next);
}
head.next 抛出错误
/LinkedListTest.m: test failure: -[LinkedListTest testAdd] failed: ((testList.head.next) != nil) failed: throwing "-[__NSCFNumber next]: unrecognized selector sent to instance 0x8d75720"
=c
【问题讨论】:
-
第一个告诉
testList.head返回NSCFNumber并且它没有名为next的属性 -
只是为了让您知道,如果您不分享所有代码,没有人会提供帮助。我无法访问 pastebin,所以我不会帮忙,就这么简单。这也与
xcode IDE无关。
标签: ios objective-c ios7