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