I have a large NSArray of names, I need to get random 4 records (names) from that array, how can I do that?
相关问题
- 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
- why 48 bit seed in util Random class?
If you prefer a Swift Framework that also has some more handy features feel free to checkout HandySwift. You can add it to your project via Carthage then use it like this:
There is also an option to get multiple random elements at once:
I hope this helps!
I made a caregory called
NSArray+RandomSelection
. Just import this category into a project, and then just useHere's the implementation:
NSArray+RandomSelection.h
NSArray+RandomSelection.m