如何从领域结果创建数组

时间:2018-04-25 11:13:00

标签: swift realm

我想从Realm结果

创建一个数组
[0] SaveCalendar {
    id = 1;
    color = #F0C0DD;
    date = 2018-04-11 14:05:00;
},
[1] SaveCalendar {
    id = 2;
    color = #EDBBB5;
    date = 2018-04-12 13:07:00;
},

我想像这样转换它:[#F0C0DD : 2018-04-11 14:05:00 , #EDBBB5 : 2018-04-12 13:07:00]

1 个答案:

答案 0 :(得分:0)

试试此代码

    var calendarList =  Array(realm.objects(SaveCalendar.self)) 
    var strCalendarList = [[String:String]]()

    for calender in calendarList {
        strCalendarList.append(["\(calender.color)":"\(calender.date)"])
    }

    print(strCalendarList)

结果 [["#EDBBB5": "2018-04-11 14:05:00"], ["#EDBBB5": "2018-04-11 14:05:00"]]