I have the following case. I import data from an xml feed and from facebook graph api, in this case posts. I want to merge this data in a array and sort this on the included date data.
I have now the following:
[containerArray addObject: [NSMutableArray arrayWithObjects: created_time, message, picture, fbSource, nil ]
];
This creates a 2-dimensional array, but i want to order all the entries on created_time.
How can i best solve this problem? Thnx in advance!!
Create a data class containing the necessary instance variables instead of the mutable array. Then you can use the various sort method of the NSArray class, for example
sortedArrayUsingDescriptors.A sort could look like this:
EDIT
To quote Mr. Fowler from his book Refactoring: Improving the Design of Existing Code.
That’s what we want to do here. Let’s create a simple Posts class. You can easily add your custom initializer which accepts the four values as parameters, or even a convenience class method to return an autoreleased object later on. This is just a basic skeleton:
Post.h
Post.m
EDIT 2
Adding a Post object to your array: