I have a NSMutableArray called allItems which has the following ProductData object.
Each object has cid, cname, ctype and cimage. As you see below json object is not coming in order. However, cid is a indicator for ordering.
I wonder how do you order based on cid?
[
{
"cid": "2",
"cname": "Meats",
"ctype": "main",
"cimage": "baked_chicken.jpg"
},
{
"cid": "1",
"cname": "Dips",
"ctype": "side",
"cimage": "stuffed_eggplant.jpg"
},
{
"cid": "4",
"cname": "Sandwiches",
"ctype": "sand",
"cimage": "chickenshawarma.jpg"
},
{
"cid": "3",
"cname": "Appetizers",
"ctype": "side",
"cimage": "rice_lentils.jpg"
},
{
"cid": "5",
"cname": "Desserts",
"ctype": "dsrt",
"cimage": "cake.jpg"
}]
If I use the sortDescriptior, it partially works. The issue that I am facing, when it sorts, it first display cid 1 and then cid 10 and then cid 2.
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"cid" ascending:YES];
[allItems sortUsingDescriptors:@[sortDescriptor]];