Tag: nsdictionary

如何按降序排列date数组

我有一个NSDictionaryparsing为一个数组的一个元素是date,我试着用[startimeArray sortUsingSelector:@selector(compare:)]; (starttimeArray)是我的date,但它只能按升序排列。 我怎么能按降序排列 谢谢

使用AFNetworking发送嵌套的JSON

要将注册数据发送到服务器,我使用JSON的forms如下: {"regData": { "City":"Some City", "Country":"Some Country", "Email_Id":"abc@gmail.com", "MobileNumber":"+00xxxxxxxxxx", "UserName":"Name Of user" } } 这是如何发送。 NSURL * url = [[NSURL alloc] initWithString:registerUrlString]; AFHTTPClient * httpClient = [[AFHTTPClient alloc] initWithBaseURL:url]; httpClient.parameterEncoding = AFJSONParameterEncoding; [[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES]; NSDictionary * params = @{@"regData": @{ @"City": self.cityField.text, @"Country": self.countryField.text, @"Email_Id": self.emailField.text, @"MobileNumber": self.numberField.text, @"UserName": self.userName.text, } }; NSMutableURLRequest * […]

字典和数组有什么区别?

字典和数组之间有什么区别,特别是在使用PLIST文件时? 使用其中一个的优点是什么? 谢谢!

如何从NSDictionary中删除对象

您好我有一个NSdictionary,其中我添加一个关键“国家”的数组。 现在我把这个字典的值放到数组中,并按照alpahbatical的顺序对数组进行sorting。现在我想把这个数组添加到我的字典中(也就是我想用新的已sorting数组更新我的字典,并从中删除旧数组)。 ……. 这个怎么做 我的代码如下 NSArray *countriesToLiveInArray = [NSArray arrayWithObjects:@"Iceland", @"Greenland", @"Switzerland", @"Norway", @"New Zealand", @"Greece", @"Italy", @"Ireland", nil]; NSDictionary *countriesToLiveInDict = [NSDictionary dictionaryWithObject:countriesToLiveInArray forKey:@"Countries"]; NSArray *tmpary = [countriesToLiveInDict valueForKey:@"Countries"]; NSLog(@"ary value is %@",ary); NSArray *sortedArray = [tmpary sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]; NSLog(@"sortedArray is %@",sortedArray); 在这里,我想删除countriesToLiveInArray,并用具有相同的键值,即国家在此先感谢sortedArray取代它。

将字块中的块保留

我有我自己的方法,把块作为一个参数。 我想跟踪在NSDictionary内的块。 将字块添加到字典的最佳方法是什么? 我试过这个代码,但执行下面的行(setObject …)后,字典仍然是空的。 我认为这是因为该块不是NSObjecttypes。 但是,这样做的正确方法是什么? – (void)startSomething:(NSURLRequest*)request block:(void (^)(NSURLResponse*, NSData*, NSError*))handler { NSURLConnection *connection = [NSURLConnection connectionWithRequest:request delegate:self]; [pendingRequests setObject:handler forKey:connection]; } 编辑: 没关系。 我不知道我在想什么。 3分: 块是objc对象 Typo:setObject应该是setValue forKey是一个string,所以它应该是[连接描述]或类似的东西 无论如何,我现在解决我的问题是这样的: – (void)startSomething:(NSURLRequest*)request block:(void (^)(NSURLResponse*, NSData*, NSError*))handler { NSURLConnection *connection = [NSURLConnection connectionWithRequest:request delegate:self]; [pendingRequests setValue:handler forKey:[connection description]]; } – (void)connectionDidFinishLoading:(NSURLConnection *)connection { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, […]

Swift(beta 3)“NSDictionary? 不符合协议“可衡量”“

自从更新到最新的Xcode 6 DP3以来,我在Swift代码中已经有了一些警告和错误。 大多数已经通过采用新改变的语法来解决,但是有一个似乎很奇怪的错误。 下面的代码给出错误Type 'NSDictionary?' does not conform to protocol 'Equatable' Type 'NSDictionary?' does not conform to protocol 'Equatable' : if (launchOptions != nil && launchOptions![UIApplicationLaunchOptionsRemoteNotificationKey] != nil) { 有没有人有办法解决吗? 我可能忽略这里简单的东西..! 谢谢

将NSDictionary转换为XML

我需要以XML格式发布数据。 服务器接受特定的xml格式。 我不想手动编写XML,我想要做的是创build一个NSMutableDictionary填充它,并从NSMutableDictionary转换它的XML。 我使用这个: [NSPropertyListSerialization dataWithPropertyList:data format:NSPropertyListXMLFormat_v1_0 options:0 示例返回是这样的: <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"> <dict> <key>email</key> <string>me@n.net</string> <key>invoice_date</key> <string>2012-10-11T10:35:09Z</string> <key>invoice_lines</key> <array> <dict> <key>product_id</key> <integer>1021493</integer> <key>quantity</key> <real>1</real> <key>retail_price</key> <real>110</real> </dict> </array> <key>payments</key> <array> <dict> <key>amount</key> <real>288.5</real> </dict> <dict> <key>payment_type_id</key> <integer>1</integer> </dict> </array> 上述格式不能从服务器读取。 服务器需要像这样的XML提要。 <invoice> <invoice_date>2012-10-11T10:35:09Z</invoice_date> <email>me@n.net</email> <invoice_lines type="array"> <invoice_line> <product_id>1021505</product_id> <quantity>1</quantity> <retail_price>45</retail_price> […]

为什么string在引用中显示在NSDictionary,但其他人不?

所以我有一个NSMutableDictionary,我填充,但是当我输出的内容NSLog,在for循环中input的项的键和值显示不同,最后的NSLog调用甚至不输出任何东西。 这里发生了什么??? 请帮忙! 为什么在for循环中添加条目的引号? NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys: numberOfPhotosAsString, @"PackageFileCount", wtID, @"wtID", uploadType, @"type", nil]; for (int i= 0; i < photos.count; i++) { NSString *finalFileName = [fileNameBase stringByAppendingFormat:@"%i", i]; [params setObject:[[fileNames objectAtIndex:i] stringByAppendingString:@".jpg"] forKey:finalFileName]; // This one doesn't do anything differently: //[params setValue:[[fileNames objectAtIndex:i] stringByAppendingString:@".jpg"] forKey:[fileNameBase stringByAppendingFormat:@"%i", i]]; } NSLog(@"Params: %@", params); NSLog(@"Value: […]

NSPredicate匹配“NSDatabase中包含一个string的值的任何条目”

我有一系列字典,类似于以下内容: ( { 黑色=“?”; date=“????。??” 结果=“*”; SourceDate =“2007.10.24”; 白=“配对模式#1”; }, { 黑色=“?”; date=“????。??” 结果=“*”; SourceDate =“2008.10.24”; 白=“关于本出版物”; } ) 我想让用户能够在“白色”和“黑色”字段内或任何字段内search文本。 我有一个NSPredicate来做特定的领域: predicate = [NSPredicate predicateWithFormat:@"self.Black contains[cd] %@ or self.White contains[cd] %@", searchText, searchText]; [filteredGames addObjectsFromArray:[games filteredArrayUsingPredicate:predicate]]; 我想不出如何为一个谓词返回一个谓词,这个谓词将返回与文本匹配的任何对象的字典。 即我可以search“2007”,它会返回第一个字典,但不是第二个。 我尝试了我自己并不真正期待的“自我。*”,并且还“更自我。所有的价值”,这是我更有希望的。 事实上我并不知道密钥是什么,因此需要一些不太具体的东西。 有什么build议么?

Obj-C简单的方法来从NSObject的属性转换为NSDictionary?

我遇到了一些我最终想到的东西,但是认为可能有更高效的方法来实现它。 我有一个对象(一个采用了MKAnnotation协议的NSObject),它具有许多属性(标题,副标题,纬度,经度,信息等)。 我需要能够将这个对象传递给另一个对象,它想使用objectForKey方法从它提取信息作为一个NSDictionary(因为这是从另一个视图控制器得到的)。 我最终做的是创build一个新的NSMutableDictionary,并使用setObject:forKey来传输每一个重要的信息,然后我只是传递新创build的字典。 有没有更简单的方法来做到这一点? 以下是相关的代码: // sender contains a custom map annotation that has extra properties… – (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([[segue identifier] isEqualToString:@"showDetailFromMap"]) { DetailViewController *dest =[segue destinationViewController]; //make a dictionary from annotaion to pass info NSMutableDictionary *myValues =[[NSMutableDictionary alloc] init]; //fill with the relevant info [myValues setObject:[sender title] forKey:@"title"] ; [myValues […]