0
我試圖將數據添加到嵌套在其他字典內的NSMutableDictionary
。代碼之前,增加了數據將數據添加到另一個NSDictionary中的NSDictionary
啓動輸出運行
DayData Dictionary { //DayData Dictionary
Monday = { //events Dictionary
trip1 = { //eventData Dictionary
numItems = 9items;
time = "5:00";
tripName = beachfucking;
};
};
Thursday = {
trip1 = {
numItems = 9items;
time = "5:00";
tripName = beachfucking;
};
};
Tuesday = {
trip1 = {
numItems = 9items;
time = "5:00";
tripName = beachfucking;
};
};
Wendsday = {
trip1 = {
numItems = 9items;
time = "5:00";
tripName = beachfucking;
};
};
}
代碼生成此輸出
NSMutableDictionary *eventData = [[NSMutableDictionary alloc]initWithObjects:@[@"5:00",@"9items",@"beachfucking"] forKeys:@[@"time",@"numItems",@"tripName"]];
NSMutableDictionary *event = [NSMutableDictionary dictionaryWithObjectsAndKeys:
eventData,@"trip1",nil];
NSMutableDictionary *dayData = [NSMutableDictionary dictionaryWithObjectsAndKeys:
event,@"Monday",event,@"Tuesday",
event,@"Wendsday",event,@"Thursday",nil];
我現在嘗試解決問題。在這裏我創建一個新的事件NSDictionary
然後將該數據添加到DayData Dictionary。但輸出不正確。星期一隻有假設時,每週的每一天都會獲得「trip2」數據集。從代碼
NSMutableDictionary *event2 = [NSMutableDictionary dictionaryWithObjectsAndKeys:
eventData,@"trip2",nil];
[[dayData objectForKey:@"Monday"] addEntriesFromDictionary:event2];
電流輸出錯上述
2016-12-24 01:56:41.261329 test1[10098:380349] {
Monday = {
trip1 = {
numItems = 9items;
time = "5:00";
tripName = beachfucking;
};
trip2 = {
numItems = 9items;
time = "5:00";
tripName = beachfucking;
};
};
Thursday = {
trip1 = {
numItems = 9items;
time = "5:00";
tripName = beachfucking;
};
trip2 = {
numItems = 9items;
time = "5:00";
tripName = beachfucking;
};
};
Tuesday = {
trip1 = {
numItems = 9items;
time = "5:00";
tripName = beachfucking;
};
trip2 = {
numItems = 9items;
time = "5:00";
tripName = beachfucking;
};
};
Wendsday = {
trip1 = {
numItems = 9items;
time = "5:00";
tripName = beachfucking;
};
trip2 = {
numItems = 9items;
time = "5:00";
tripName = beachfucking;
};
};
}
通知TRIP2如何爲每週七天填寫。
是的,但我創建nsdictionary對象event2,然後將其添加到週一的關鍵。 – cheesey
我看到很好的答案謝謝! – cheesey