如果你真的堅定的關於在字典存儲對象,如果你正在處理字符串,你總是可以添加您的所有字符串用逗號在一起分開的,然後當你從鍵檢索對象,你將擁有準csv格式的所有對象!然後,您可以輕鬆地將該字符串解析爲一個對象數組。
下面是一些示例代碼,你可以運行:
NSString *forename = @"forename";
NSString *surname = @"surname";
NSString *reminderDate = @"10/11/2012";
NSString *code = @"code";
NSString *dummy = [[NSString alloc] init];
dummy = [dummy stringByAppendingString:forename];
dummy = [dummy stringByAppendingString:@","];
dummy = [dummy stringByAppendingString:surname];
dummy = [dummy stringByAppendingString:@","];
dummy = [dummy stringByAppendingString:reminderDate];
dummy = [dummy stringByAppendingString:@","];
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
[dictionary setObject:dummy forKey:code];
然後去檢索和分析對象在詞典:
NSString *fromDictionary = [dictionary objectForKey:code];
NSArray *objectArray = [fromDictionary componentsSeparatedByString:@","];
NSLog(@"object array: %@",objectArray);
它可能不是那樣乾淨有字典的層像dreamlax建議的那樣,但是如果你正在處理一個字典,你想爲一個鍵存儲一個數組,而且該數組中的對象本身沒有特定的鍵,這是一個解決方案!
不要只是downvote,讓我知道什麼是錯的,以便我可以修復它! – dreamlax 2014-06-20 09:29:10