开发者

How can i sort NSMutableArray iphone?

I have a scenario where the application retrieves information from a json php into an NSMutableArray. My question is as follows ; how can i sort the elements by the "time" field?. Also how can i only display the elements that have 'day' as "monday"? (what would the if statement look like?). Thanks for any help on this.

Also the information in the NSMutableArray looks as follows ;

   Array: (
            {
            Code = 2COS402;
            Core = Yes;
            Credit = 15;
            Day = Monday;
            Facilities = Full;
            Level = 4;
            Module = "Introduction to Computer Programming";
            "Room_Empty" = Yes;
            Teacher = "Mark James";
            Time = "10:45";
            id = 1;
        },
            {
            Code = 2GDP401;
            Core = Yes;
            Credit = 15;
            Day = Monday;
            Facilities = Full;
       开发者_开发百科     Level = 4;
            Module = "Fundamentals of Interactive Games";
            "Room_Empty" = No;
            Teacher = "Will Smith";
            Time = "09:00";
            id = 4;
        },
            {
            Code = 2GDP501;
            Core = Yes;
            Credit = 15;
            Day = Monday;
            Facilities = Full;
            Level = 4;
            Module = "Games Play Design";
            "Room_Empty" = Yes;
            Teacher = "Frank Sinatra";
            Time = "15:00";
            id = 6;
        }
    )


You can check sortUsingComparator: or sortUsingSelector: methods of NSMutableArray. Of course, you'll need to define your custom NSComparator or implement a custom method to do that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜