Tag: nsdictionary

将plist加载到iOS TableView中

我有一个plist( images.plist )以下内容 正如你所看到的,每个项目都有一个从0到19的数字键。 每个项目也有两个string(fileName和fileInfo)。 我试图加载所有的文件名到一个TableView。 这是我的尝试: RosterMasterViewController.h @interface RosterMasterViewController : UITableViewController @property (nonatomic, strong) NSDictionary *roster; @end RosterMasterViewController.m @implementation RosterMasterViewController @synthesize roster = _roster; … // This is in my 'viewDidLoad' NSString *file = [[NSBundle mainBundle] pathForResource:@"images" ofType:@"plist"]; self.roster = [NSDictionary dictionaryWithContentsOfFile:file]; 这就是我想如何加载文件名到原型单元格。 RosterMasterViewController.m – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier […]

使用NSdictionary中的数据初始化NSArray

我从URL接收数据,把它放在NSDictionary,然后我需要为每个标签创buildNSArray。 我的NSDictionary看起来像: ( { id = { text = 1; }; logo = { text = "url 1"; }; name = { text = "some name 1"; }; }, { id = { text = 2; }; logo = { text = "url 2"; }; name = { text = "some name 2"; }; }, […]

使用块将NSDictionary转换为string?

我相信有一种方法可以使用块来做到这一点,但我无法弄清楚。 我想把一个NSDictionary变成url风格的参数string。 如果我有一个NSDictionary看起来像这样: dict = [NSDictionary dictionaryWithObjectsAndKeys:@"blue", @"color", @"large", @"size", nil]]; 那我怎么把它变成一个看起来像这样的string: "color=blue&size=large" 编辑 感谢下面的线索。 这应该做到这一点: NSMutableString *parameterString; [dict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { [parameterString appendFormat:@"%@=%@&", key, obj]; }]; parameterString = [parameterString substringToIndex:[string length] – 1];

如何将内存中的NSDictionary上传到Dropbox,IOS

我有一个xmlstring,我想上传一个.plist到一个保pipe箱文件夹。 目前我创build一个NSDictionary并创build一个临时文件夹,我将该词典编写为该临时文件夹的plist,并将该.plist上传到该临时文件夹中的Dropbox。 我猜这不是一个好的编程解决scheme; 这工作正常 if([title isEqualToString:@"Upload to Dropbox"]) { //pass string in memory to nsdictionary NSData * data = [_uploadPlistString dataUsingEncoding:NSUTF8StringEncoding]; NSString *errorDesc = nil; NSPropertyListFormat format; NSDictionary *uploadFile= (NSDictionary*)[NSPropertyListSerialization propertyListFromData:data mutabilityOption:NSPropertyListMutableContainersAndLeaves format:&format errorDescription:&errorDesc]; //create a temp folder NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"temp"]; NSLog(@"documents […]

过滤NSArray中字典对象的比较

我有一个字典数组,我需要以非常特定的方式进行过滤。 这是最容易解释的例子。 假设我有一个包含以下三个字典的数组,其中@“threadId”,@“subject”,@“messageId”是键: NSDictionary #1: @"threadId" : @"1234" @"subject" : @"hello" @"messageId" : @"0001" NSDictionary #2: @"threadId" : @"1234" @"subject" : @"hello" @"messageId" : @"0002" NSDictionary #3: @"threadId" : @"9101" @"subject" : @"goodbye" @"messageId" : @"0005" 我正在考虑任何具有相同值的字典,它们都是@“threadId”和@“subject”是重复的,即使@“messageId”是不同的。 因此,我认为字典1和字典2是重复的,我想从上面的数组中删除EITHER字典1或字典2(不是两个)。 换句话说,我想过滤所有三个字典的原始数组到一个新的数组,包含他们的字典1和3或字典2和3。 到目前为止,我所做的所有尝试都导致了过多的for循环,其中我尝试通过threadId对字典进行sorting和分隔,但之后我陷入了比较部分。 我已经看过谓词过滤,但它看起来像它只能删除符合特定条件的对象,与其他对象无关。 NSSet将无法工作,因为我认为是重复的对象实际上并不重复。 我想知道是否有人可以提出一个执行此过滤的一般策略。

按date分组NSDictionary

我有一个NSDictionary,我想分组创builddate对象的数组 主NSDictionary的例子: ({ date = "2014-04-27"; group = "yellow.png"; length = 180; }, { date = "2014-04-28"; group = "blue.png"; length = 180; }, { date = "2014-04-27"; group = "blue.png"; length = 120; }) 我想分组的东西类似于: 2014-04-27 = ( { date = "2014-04-27"; group = "yellow.png"; length = 180; }, { date = "2014-04-27"; group […]

基于值嵌套NSDictionary

我从库中的数据返回这个: NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:distanceNumber,@"distance",idChallengerN,@"idChallenger",dateFrom, @"date", nil]; [_array addObject:dict]; 如果我打印_array这是有结果: { date = "2015-07-31 14:50:40 +0000"; distance = "-1"; idChallenger = 43; }, { date = "2015-07-31 16:18:57 +0000"; distance = "-1"; idChallenger = "-1"; }, { date = "2015-07-31 16:19:05 +0000"; distance = "-1"; idChallenger = "-1"; }, 没关系,现在我应该得到每个date并根据星期这个_array … 我试过了: NSMutableDictionary *tempDic […]

带@符号的NSDictionary键

像这样在这里问如果一个键启动@符号使用valueForKeyPath on NSDictionary? 如果我必须使用像“@ID”和“@Name”(服务器端的限制,我没有控制命名)键的NSDictionary我怎么能解决这个问题? 现在,每当我尝试访问这种密钥的应用程序只是崩溃。

在NSArray内的NSDictionary中排列NSDates?

目前在我的应用程序,我有一个NSArray,我从NSUserDefaults加载。 NSArray中的每个对象都是一个NSDictionary,它有大约5个不同的键。 我根据他们内部的NSDates重新订购NSDictionarys 。 我不想单独排列NSDates。 我试图用这个代码做到这一点: NSComparator sortByDate = ^(id dict1, id dict2) { NSDate* n1 = [dict1 objectForKey:@"Date"]; NSDate* n2 = [dict2 objectForKey:@"Date"]; return (NSComparisonResult)[n1 compare:n2]; }; [self.cellArray sortUsingComparator:sortByDate]; 即使代码被执行,也没有任何反应。 我很困惑,但如何重新订购NSDictionarys基于内部的东西。 任何人都可以提供任何见解吗? 谢谢!

NSDictionary添加NULL keyvalue

所以我创build了一个NSDictionary,它提供了一个要使用的方法数据,但是keys数组中的一些键值不会总是被值填充。假设我有18个键(我这样做)..我可能只有在一次通话中使用5,而在另一个通话中使用5,或者在我的代码中的某些时候使用18。 我想知道的是我怎样才能将NULL值添加到这些键,所以稍后当我通过keyvalue对看,我可以看到哪些键我需要担心,哪些我可以忘记? 所以问题是,如果我想不添加任何/ null的一个关键如何做到这一点,而不会造成错误,或认为它的数组结尾nil .. 这是我目前的,但只要我尝试阅读NSDicionary它给我一个不好的EXE错误 NSDictionary * sendSeriesDictionary = [[NSDictionary alloc] init]; NSArray *keys = [NSArray arrayWithObjects:@"Code", @"MaID", @"MoID", @"SuID",@"SMID",@"Ye",@"KID",@"KBlID",@"KBk",@"CaID",@"Caer",@"Loe",@"Kepe",@"KTGroup",@"Cesc",@"LID",@"IN",@"LaID", nil]; NSArray *objects = [NSArray arrayWithObjects: NULL, manufactureIdString, modelIdString, subModelIdString, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, nil]; sendSeriesDictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys]; 只是为了让你知道键名将被改变,这只是为了testing/例如如何做到这一点。 任何帮助将不胜感激。