How to select one object from a NSArray?

Posted by 0SX on Stack Overflow See other posts from Stack Overflow or by 0SX
Published on 2010-12-25T01:40:17Z Indexed on 2010/12/25 1:54 UTC
Read the original article Hit count: 589

Filed under:
|
|
|
|

First of all Merry Christmas to everyone!!! Currently I have a NSArray that has parsed content in it. When I do a NSLog of the array it prints out 20 objects with the parsed content that I needed. Like so:

2010-12-24 20:27:32.170 TestProject[48914:298] SomeContent
2010-12-24 20:27:32.172 TestProject[48914:298] SomeContent1
2010-12-24 20:27:32.172 TestProject[48914:298] SomeContent2
2010-12-24 20:27:32.173 TestProject[48914:298] SomeContent3
2010-12-24 20:27:32.173 TestProject[48914:298] SomeContent4
2010-12-24 20:27:32.173 TestProject[48914:298] SomeContent5
2010-12-24 20:27:32.174 TestProject[48914:298] SomeContent6
2010-12-24 20:27:32.175 TestProject[48914:298] SomeContent7
2010-12-24 20:27:32.176 TestProject[48914:298] SomeContent8
2010-12-24 20:27:32.176 TestProject[48914:298] SomeContent9
2010-12-24 20:27:32.177 TestProject[48914:298] SomeContent10
2010-12-24 20:27:32.177 TestProject[48914:298] SomeContent11
2010-12-24 20:27:32.177 TestProject[48914:298] SomeContent12
2010-12-24 20:27:32.179 TestProject[48914:298] SomeContent13
2010-12-24 20:27:32.179 TestProject[48914:298] SomeContent14
2010-12-24 20:27:32.180 TestProject[48914:298] SomeContent15
2010-12-24 20:27:32.180 TestProject[48914:298] SomeContent16
2010-12-24 20:27:32.181 TestProject[48914:298] SomeContent17
2010-12-24 20:27:32.181 TestProject[48914:298] SomeContent18
2010-12-24 20:27:32.190 TestProject[48914:298] SomeContent19

However, I don't need every object at once. I need to be able to pick out one object at a time so I can put each object into a string of it's own. If anyone knows a easier way to do this then what I'm trying to please let me know. Anyways, I need to be able to choose just one object depending on what object I need. For example, let's say I only need object #5 and not all the array, how can this be done so I can put it into a string? I'm thinking I might have to use the index feature but I'm not sure how to set it up properly. Here is my NSArray that I'm working with:

NSArray* myArray = [document selectElements: @"div.someContent"];
NSMutableArray* results = [NSMutableArray array];
for (Element* element in myArray){
    NSString* snipet = [element contentsSource];
    [results addObject: snipet];
    NSLog(@"%@", snipet);
}
NSLog(@"%i",myArray.count);

I've already spent several hours trying to achieve this but my knowledge with array's is limited even with me reading the documentation. :-( Any help is much appreciated. Thanks

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c