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
82
votes
3 answers

NSDictionary Key For Value/Object?

Can we get the key for an object in an NSDictionary by passing a particular value or object?
Syed Absar
  • 2,274
  • 1
  • 26
  • 45
78
votes
9 answers

Check key exists in NSDictionary

how can I check if this exists?: [[dataArray objectAtIndex:indexPathSet.row] valueForKey:@"SetEntries"] I want to know whether this key exists or not. How can I do that? Thank you very much :) EDIT: dataArray has Objects in it. And these objects…
cocos2dbeginner
  • 2,185
  • 1
  • 31
  • 58
69
votes
6 answers

Best way to sort an NSArray of NSDictionary objects?

I'm struggling with trying to sort an array of dictionaries. My dictionaries have a couple of values of interest, price, popularity etc. Any suggestions?
iOSDevil
  • 1,786
  • 3
  • 16
  • 29
67
votes
11 answers

Sorting NSArray of dictionaries by value of a key in the dictionaries

I have an array populated by dictionaries, and I need to sort the array alphabetically by the values of one of the keys of the dictionaries. This is my array: tu dictus: ( { brand = Ryul; productTitle = Any; quantity = 1; …
manuelBetancurt
  • 15,428
  • 33
  • 118
  • 216
67
votes
3 answers

How can we store into an NSDictionary? What is the difference between NSDictionary and NSMutableDictionary?

I am developing an application in which I want to use an NSDictionary. Can anyone please send me a sample code explaining the procedure how to use an NSDictionary to store Data with a perfect example?
Pradeep Reddy Kypa
  • 3,992
  • 7
  • 57
  • 75
61
votes
9 answers

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

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…
Namratha
  • 16,630
  • 27
  • 90
  • 125
61
votes
4 answers

convert NSDictionary to NSString

I am trying to put the content of an NSDictionary into an NSString for testing, But have no idea how to achieve this. Is it possible? if so how would one do such a thing? The reason I am doing this, Is I need to check the content of a NSDicitonary…
C.Johns
  • 10,185
  • 20
  • 102
  • 156
59
votes
6 answers

NSDictionary to NSData and NSData to NSDictionary in Swift

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", …
IanTimmis
  • 815
  • 1
  • 8
  • 16
55
votes
5 answers

Store selector as value in an NSDictionary

Is there a way to store a selector in an NSDictionary, without storing it as an NSString?
synic
  • 26,359
  • 20
  • 111
  • 149
48
votes
5 answers

iOS: Why can't I set nil to NSDictionary value?

This might be very basic question but I was wondering why can't I assign nil as NSDictionary value? I have following statement many places in my code. If [q objectForKey:@"text"] is nil then App is crashing. NSMutableDictionary *dict =…
Paresh Masani
  • 7,474
  • 12
  • 73
  • 139
46
votes
4 answers

Beautify NSLog of NSArray & NSDictionary

I'm dealing with deeply nested NSArray's and NSDictionary's and it's very time consuming to say the least. [data objectatindex:0] valueForKey:@"blah"] etc etc Does anyone know of a nice iOS category to recursively log the structure, highlight the…
iOSDevil
  • 1,786
  • 3
  • 16
  • 29
46
votes
6 answers

Convert NSArray to NSDictionary

How can I convert an NSArray to an NSDictionary, using an int field of the array's objects as key for the NSDictionary?
johnl
  • 557
  • 2
  • 5
  • 7
45
votes
4 answers

How can I convert an NSDictionary to an NSMutableDictionary?

I have an existing NSDictionary that has: { "charts_count" = 2; "created_at" = "2010-04-12T16:37:32Z"; exchange = NASDAQ; "followers_count" = 259; id = 8404; industry = ""; "messages_count" = 1436; ric =…
Sheehan Alam
  • 60,111
  • 124
  • 355
  • 556
45
votes
2 answers

Can i sort the NSDictionary on basis of key in Objective-C?

Can I sort the NSDictionary on basis of key?
suse
  • 10,503
  • 23
  • 79
  • 113
44
votes
3 answers

Casting a CFDictionaryRef to NSDictionary?

I have the code (stripped down): CFDictionaryRef *currentListingRef; //declare currentListingRef here NSDictionary *currentListing; currentListing = (NSDictionary *) currentListingRef; And then I get the error: Cast of a non-Objective-C pointer…
johnluttig
  • 750
  • 1
  • 9
  • 24