nsdictionary

sort NSDictionary values by key alphabetical order

孤街浪徒 提交于 2019-11-28 19:16:19
I can get an array of dictionary keys sorted by values, but how to I get an array of values sorted by dictionary keys? I've been looking everywhere with no luck. Any help appreciated. This might work: NSArray * sortedKeys = [[dict allKeys] sortedArrayUsingSelector: @selector(caseInsensitiveCompare:)]; NSArray * objects = [dict objectsForKeys: sortedKeys notFoundMarker: [NSNull null]]; or in Swift let objects = dict.keys.sorted().flatMap{ dict[$0] } or let objects = dict.sorted{ $0.0 < $1.0 }.map{ $1 } …and that is why you should start developing in Swift 😄 One way is to construct the array of

how to remove object from NSDictionary

人走茶凉 提交于 2019-11-28 19:12:10
Hi i am having a NSdictionary in which i am adding a array with key "countries ". Now i take the value of this dictionary into array and sort the array in alpahbatical order .Now i want to add this array into my Dictionary (that is i want to update my dictionary with new sorted array and remove the old array from it )........ how to do this My code is as follows NSArray *countriesToLiveInArray = [NSArray arrayWithObjects:@"Iceland", @"Greenland", @"Switzerland", @"Norway", @"New Zealand", @"Greece", @"Italy", @"Ireland", nil]; NSDictionary *countriesToLiveInDict = [NSDictionary

Filtering NSDictionary with predicate

帅比萌擦擦* 提交于 2019-11-28 18:25:08
I am using a NSDictionary that itself contains dictionaries some keys and its values.The format is like , { "1" = { "key1" = "ss", "key2" = "rr", "name" = "nm" }, "2" = { "key1" = "tt", "key2" = "vv", "name" = "gf" }, "3" = { "key1" = "nm", "key2" = "vv", "name" = "gf" }, "4" = { "key1" = "tt", "key2" = "vv", "name" = "gf" }, } I need to filter with the case that key1 should be "tt" and key2 should "vv" using NSPredicate. Assume that mainDict = { "1" = { "key1" = "ss", "key2" = "rr", "name" = "nm" }, "2" = { "key1" = "tt", "key2" = "vv", "name" = "gf" }, "3" = { "key1" = "nm", "key2" = "vv",

Store NSDictionary in keychain

我的未来我决定 提交于 2019-11-28 17:35:13
问题 It is possible to store a NSDictionary in the iPhone keychain, using KeychainItemWrapper (or without)? If it's not possible, have you another solution? 回答1: You must properly serialize the NSDictionary before storing it into the Keychain. Using: [dic description] [dic propertyList] you will end up with a NSDictionary collection of only NSString objects. If you want to maintain the data types of the objects, you can use NSPropertyListSerialization . KeychainItemWrapper *keychain = [

How to pass a NSDictionary with postNotificationName:object:

╄→尐↘猪︶ㄣ 提交于 2019-11-28 17:29:26
问题 I am trying to pass an NSDictionary form a UIView to a UIViewController using NSNotificationCenter. The dictionary works fine at the time the notification is posted, but in the receiving method I am unable to access any of the objects in the dictionary. Here is how I am creating the dictionary and posting the notification... itemDetails = [[NSDictionary alloc] initWithObjectsAndKeys:@"Topic 1", @"HelpTopic", nil]; [[NSNotificationCenter defaultCenter] postNotificationName:@"HotSpotTouched"

NSDictionary to NSData and NSData to NSDictionary in Swift

孤街醉人 提交于 2019-11-28 16:57:58
I am not sure if I am using the dictionary or the data object or both incorrectly. I m trying to get used to the switch to swift but I'm having a little trouble. var dictionaryExample : [String:AnyObject] = ["user":"UserName", "pass":"password", "token":"0123456789", "image":0] // image should be either NSData or empty let dataExample : NSData = dictionaryExample as NSData I need the NSDictionary to encode to an NSData object as well as taking that NSData object and decode it into a NSDictionary . Any help is greatly appreciated, thanks. Leo You can use NSKeyedArchiver and NSKeyedUnarchiver

How to add to an NSDictionary

Deadly 提交于 2019-11-28 16:17:16
I was using a NSMutableArray and realized that using a dictionary is a lot simpler for what I am trying to achieve. I want to save a key as a NSString and a value as an int in the dictionary. How is this done? Secondly, what is the difference between mutable and a normal dictionary? Eiko A mutable dictionary can be changed, i.e. you can add and remove objects. An immutable is fixed once it is created. create and add: NSMutableDictionary *dict = [[NSMutableDictionary alloc]initWithCapacity:10]; [dict setObject:[NSNumber numberWithInt:42] forKey:@"A cool number"]; and retrieve: int myNumber = [

How to get the duration of an audio file in iOS?

安稳与你 提交于 2019-11-28 15:10:08
问题 NSDictionary* fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filename error:nil] From the file attribute keys, you can get the date, size, etc. But how do you get the duration? 回答1: In the 'File Attribute Keys' of the NSFileManager class reference you can see that there is no key to use that will return the duration of a song. All the information that the NSFileManager instance gets about a file is to do with the properties of the actual file itself within the

How to plot the markers in google maps from a dictionay in ios?

拜拜、爱过 提交于 2019-11-28 13:04:20
问题 In my app, I have done JSON parsing and I got the coordinates in the form of a dictionary, I want to use the coordinates angd plot it in the map, I have using this SBJsonParser *jsonParser = [SBJsonParser new]; NSArray *jsonData = (NSArray *) [jsonParser objectWithString:outputData error:nil]; for(int i=0;i<[jsonData count];i++) { NSDictionary *dict=(NSDictionary *)[jsonData objectAtIndex:i]; Nslog(@"%@",dict); double la=[[dict objectForKey:@"latitude"] doubleValue]; double lo=[[dict

Converting NSDictionary to XML

霸气de小男生 提交于 2019-11-28 12:38:33
I need to Post data in XML format. The server accepts a specific xml format. I don't want to write the xml by hand, what i want to do is create a NSMutableDictionary populate it and from NSMutableDictionary convert it XML. I use this: [NSPropertyListSerialization dataWithPropertyList:data format:NSPropertyListXMLFormat_v1_0 options:0 The sample return is this: <!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>