Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using NSSet vs NSDictionary

I understand that there is a difference in how elements are stored in a NSSet and a NSDictionary, https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Collections/Collections.html

But from a development point of view, when should I use NSSet vs NSDictionary? The time complexity for both is O(1)

Edit: I came across the question - Remove duplicates from an array. One solution stored the elements in a NSDictionary to remove duplicates, the other solution stored the elements in a NSSet.

I was wondering which would be a better approach

like image 915
Richa Avatar asked Feb 05 '26 13:02

Richa


1 Answers

NSSet and NSDictionary are very different. NSSet is a set of elements meanwhile NSDictionary keeps a list of key-value pairs, so you can access the Value directly when you have the Key. It's more meaningful to compare NSSet to NSArray than to NSDictionary.

like image 189
bsarr007 Avatar answered Feb 12 '26 19:02

bsarr007



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!