我该如何排序NSMutableArray iphone?

时间:2020-12-31 16:00:25

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.

我有一个场景,应用程序从json php检索信息到NSMutableArray。我的问题如下;我如何通过“时间”字段对元素进行排序?另外,我怎样才能显示“day”为“星期一”的元素? (if语句会是什么样子?)。感谢您的帮助。

Also the information in the NSMutableArray looks as follows ;

此外,NSMutableArray中的信息如下所示;

   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;
        }
    )

1 个解决方案

#1


1  

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.

您可以检查sortUsingComparator:或sortUsingSelector:NSMutableArray的方法。当然,您需要定义自定义NSComparator或实现自定义方法来执行此操作。

#1


1  

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.

您可以检查sortUsingComparator:或sortUsingSelector:NSMutableArray的方法。当然,您需要定义自定义NSComparator或实现自定义方法来执行此操作。