Nsarray and nsset actually implement similar basic functions. This is very different from other languages such as Java. nsarray's data storage method is continuous, the latter data is stored in the memory followed by the previous data, while the nsset does not need a continuous memory during storage. It is possible that the first data is stored in this place, the second data is separated from the first data. When I store the second data, I just find a place where I can put it down and save it.
So what are the benefits of doing so?
Because nsset is implemented using the hash idea at the underlying layer, it ensures that the objects stored in it must be unique, while Arrays can store the same objects.
Because nsset is implemented using hash, it makes it faster to query, but we cannot put a certain object after the first few elements and other related script operations.
Arrays can be used for script operations, but the query speed is slightly slower.
For example, why is the nsset query speed faster than nsarray?
When we are looking for a certain element A, in nsset, we can directly find the storage location of a through the hash value, instead, nsarray needs to traverse all the elements in front of a before finding them.