我在C中創建一個鏈接列表,並且在添加(並且是警告)時出現錯誤。objective-c:無法識別的選擇器發送到實例0x8d75720
這兩個都寫在下面。
我已經嘗試了幾件事情無濟於事...任何建議都會很棒。
[它是一個鏈表用最大的尺寸!]
//in the tester
XCTAssertNotNil(testList.head.next);
拋出這個錯誤
failed: ((testList.head.next) != nil) failed: throwing "-[__NSCFNumber next]: unrecognized selector sent to instance 0x8d75720"
這是add方法
- (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];
給出警告
Incompatibl È整數指針轉換髮送 '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'的屬性 – Rugmangathan
只是讓你知道如果你不共享你所有的代碼,沒有人會幫助。我無法訪問pastebin,所以我不會幫助,這很簡單。另外這與'xcode IDE'無關。 – Popeye