My NSMutableDictionary
contains four NSArray
s with their respective keys. These NSArray
s are of size 2 and contain 2D coordinates. I want to get the most common coordinate among them. For example, If a coordinate is common to three arrays, it would be my first choice. How can I find that any coordinate is common to at least two arrays?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
- How can I add media attachments to my push notific
Basically you want to find the pair of coordinates that has max occurences. So you can create an array of all coordinates and find its mode.
Now, U need to write a custom method to find mode of an array of coordinates (with an additional condition of frequency being >=3).
This is a working example. I'm assuming that your dictionary looks like
coordinatesDict
.Here is some code that should work, using
NSCountedSet
.In a few words: I use a
NSCountedSet
that will work as aNSSet
keeping also the numbers of occurrences (duplicates times).Then, I create a
NSArray
sorting the values descending according to the number of occurrences.I wrote explicitly the "count1/count2" comparison in case you want to apply a different value if the number of occurrences is the same.
The outputs are: