Questions tagged [nsdictionary]

A member of Apple's Objective-C framework Cocoa. NSDictionary objects manage associations of keys and values.

A member of Apple's Objective-C () framework Cocoa. NSDictionary objects manage associations of keys and values.

An instance of NSDictionary contains a set of keys and for each key an associated value.

Both keys and values must be objects. The keys must all be different from each other. Both keys and values cannot be nil.

Resources:

4108 questions
43
votes
3 answers

Convert NSDictionary to Swift Dictionary

Now I know that when swift compiles it just makes a NSDictionary, but the NSDictionary and Swift dictionaries have different syntax. Is there a way (through a loop or something) to convert a NSDictionary to a swift dictionary of the same type for…
cclloyd
  • 8,171
  • 16
  • 57
  • 104
42
votes
5 answers

Getting NSDictionary keys sorted by their respective values

I have an NSMutableDictionary with integer values, and I'd like to get an array of the keys, sorted ascending by their respective values. For example, with this dictionary: mutableDict = { "A" = 2, "B" = 4, "C" = 3, "D" = 1, } I'd…
Eric
  • 4,063
  • 2
  • 27
  • 49
39
votes
3 answers

How to pass a NSDictionary with postNotificationName:object:

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…
user278859
  • 10,379
  • 12
  • 51
  • 74
39
votes
8 answers

How can I get the first element in an NSDictionary?

I have an array of NSDictionaries. How can I pull out the first element in the dictionary? NSArray *messages = [[results objectForKey:@"messages"] valueForKey:@"message"]; for (NSDictionary *message in messages) { …
Sheehan Alam
  • 60,111
  • 124
  • 355
  • 556
38
votes
3 answers

Restoring a BOOL inside an NSDictionary from a plist file

I have a plist file which contains an array of dictionaries. Here is one of them: Fred Dictionary Name Fred isMale [box is checked] So now I am initializing my Person object with the dictionary I read from the plist file: -(id)…
William Jockusch
  • 26,513
  • 49
  • 182
  • 323
34
votes
7 answers

Serialize and Deserialize Objective-C objects into JSON

I need to serialize and deserialize objective-c objects into JSON to store in CouchDB. Do people have any example code for best practice for a general solution? I looked at a few JSON framework and they are stopped at the NSDictionary/NSArray…
PokerIncome.com
  • 1,708
  • 2
  • 19
  • 30
34
votes
4 answers

how to remove object from NSDictionary

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…
V.V
  • 3,082
  • 7
  • 49
  • 83
34
votes
11 answers

NSDictionary to NSArray?

i have a NSDictionary which looks like: { "Item1" = 2.4; "Item2" = 5.5; "Item3" = 15.6; } To use this NSDictionary Items in a Table View i have to transfer it to a NSArray, am i right? So i try: NSDictionary *dict = [myDict…
phx
  • 1,509
  • 3
  • 15
  • 18
33
votes
15 answers

Swift: How to remove a null value from Dictionary?

I'm new in Swift and I have a problem with filtering NULL values from JSON file and setting it into Dictionary. I getting JSON response from the server with null values and it crashes my app. Here is JSON response: "FirstName":…
Anvar Azizov
  • 545
  • 1
  • 6
  • 9
32
votes
3 answers

Which method of checking to see if a NSDictionary contains a particular key is faster?

I can test for the presence of a key in an NSDictionary in two ways: BOOL containsKey = [[dictionary allKeys] containsObject:foo]; BOOL containsKey = ([dictionary objectForKey:foo] != nil); which method is faster, and why?
alfwatt
  • 2,010
  • 2
  • 18
  • 29
32
votes
8 answers

Swift - Stored values order is completely changed in Dictionary

I tried to display datas which is in Dictionary format. Below, three attempts are there. First attempt, output order is completely changed. Second attempt, output order is same as input. But, in third attempt, I declared variable as NSDictionary.…
McDonal_11
  • 3,935
  • 6
  • 24
  • 55
31
votes
5 answers

Replace a value in NSDictionary in iPhone

I have a array (dataArray) of NSDictionary "item". It has datas like "david" for key "name" and "85" for key "marks" etc for 5 students. I want to replace the mark of david to 90 with respect to the array index value (ie 0 for dictionary containing…
Warrior
  • 39,156
  • 44
  • 139
  • 214
30
votes
5 answers

Convert JSON feed to NSDictionary

Where JSON_CATEGORY_DATA_URL_STRING is my feed URL, which returns fine as: [ { "group":"For Sale", "code":"SSSS" }, { "group":"For Sale", "category":"Wanted", "code":"SWNT" } ] I cannot seem…
linkingarts
  • 325
  • 1
  • 3
  • 8
30
votes
2 answers

How to create an NSDictionary in Objective-C?

I want to create an NSDictionary like this type: "zones": { { "zoneId": "1", "locations": { { "locId": "1", "locZoneId": "1", "locLatitude":…
vky
  • 475
  • 1
  • 6
  • 14
29
votes
6 answers

Display each item in an NSDictionary

I am trying to display each item in NSDictionary. I have tried using a for loop but that didn't work.
alanvabraham
  • 779
  • 2
  • 14
  • 25