0

(Xcode IOS) - I'm trying to make a method which prefetches all the images and loads them into a tableView before scrolling (using SDWebImage). Anyways:

I have an array of messages and each "message" is composed of a few different keys, PFFile, dateCreated, sender, etc...

What I need to do is take this array of @[ [PFFile], [dateCreated], [other info] ] -> @[ [PFFile] ]

In other words, I need to make an array of just the PFFiles from the entire array. I was thinking of something like this (pseudocode)

self.urls = [self.messages objectsWithKey:@[PFFiles]];

1
  • Since you're using an array, what do you mean by keys in here? More specifically what are the objects in your array? Commented Aug 12, 2014 at 0:54

2 Answers 2

1

It sounds like you are asking how to filter an array.

self.urls = [self.messages objectsAtIndexes:[self.messages indexesOfObjectsPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
    return [obj isKindOfClass:[PFFile class]];
}]];

I like this syntax because you can use a block to return YES/NO if the object passes any sort of test you might want to write and it's a one-liner.

Sign up to request clarification or add additional context in comments.

Comments

0

How about using combination of NSDictionary and NSArray ? You can put your array objects in a dictionary object.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.