|
|
#1 |
|
NSArray LastObject
Hey quick question. I have a plist that I am unpacking to add an object and re save.
Code:
NSMutableArray *exerArray = [[NSMutableArray alloc] initWithContentsOfFile:[bpc returnPath:@"exerciseLog.plist"]];
NSMutableDictionary *exerDict = [NSMutableDictionary dictionaryWithDictionary:[exerArray lastObject]];
[exerDict setValue: totalCalLabel.text forKey: itemNameTextField.text];
The way I have been doing it is to just get the count of the Array then -1 to find the last index to write to. I was just wondering if anyone new a short cut that I can write to the lastObject just as easy as I retrieve from it. I am not stuck and my method works just fine, I was just wondering? Thanks
__________________
I know more than yesterday. Lars |
|
|
|
0
|
|
|
#2 | |
|
Quote:
|
||
|
|
0
|
|
|
#3 |
|
Thanks Reason0777, I am always looking for little short cuts in code when possible. Since I saw the "lastObject" it got me wondering if there was the opposite of that.
It seems like Apple should make a change to "lastObject" and make Task that is "lastIndex" instead. This would allow you to read or replace to the last index of an array. But thanks, I was just wondering!
__________________
I know more than yesterday. Lars |
|
|
|
0
|
|
|
#4 |
|
replaceObject:atIndex: should do what you want. If you want something like replaceLastObjectWithObject: you can easily add that with a category.
|
|
|
|
0
|
|
|
#5 |
|
Yep, that is how I am currently replacing it. I have read about Categories but I have never used them. Might be a good learning experience for that. replaceObject:atIndex: required knowing the index number. Where as retrieving the last object you do not need the index number. If you could do lastObject.count in [myArray replaceObject: newObject atIndex: lastObject.count]; , although you can't of course.
It is just speculation and I don't mean to start a discussion on the subject. But I think learning / implementing categories could be a fun project for tonight. Thanks again!
__________________
I know more than yesterday. Lars |
|
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 03:49 AM.







Linear Mode
