I am new to Obj-C and Cocoa and trying to figure out how to do a sorted linked list of objects pre and post ARC.
My class would be something like
@interface Node : NSObject
{
int value;
NSValue *item;
Node *next;
}
property (strong, non atomic) value;
...
Entering a new item is done by scanning the list of Nodes and finding the insertion point by comparing the Node's value property. Where I get in trouble is when I want to remove an item from the list. My code is something like
...
Node *prevPtr = nil;
Node *curPtr = head;
while (curPtr != nil) {
if (some-condition) {
prevPtr.next = curPtr.next;
[curPtr release]; // cannot do with ARC
}
}
- Is this coding pattern compatible with Cocoa?
- Under ARC, where/when would my object get released/deallocated?
NSMutableArrayuses the same type of backing data structure as anArrayListin Java, making arbitrary insertions and deletions inefficient? I'm not saying that it does, but that could be one reason for wanting to implement a custom linked-list.