mirror of
https://github.com/Instagram/IGListKit
synced 2026-05-15 05:18:18 +00:00
Summary: Issue fixed: #1057 - [x] All tests pass. Demo project builds and runs. - [x] I added tests, an experiment, or detailed why my change isn't tested. - [ ] I added an entry to the `CHANGELOG.md` for any breaking changes, enhancements, or bug fixes. - [x] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/.github/CONTRIBUTING.md) Hello again everyone! I was having a play with integrating Realm with IGListKit again and I noticed this issue detailing the macOS app featuring several build warnings. This PR: * Updates the settings of both the macOS example project, and the Pods project to the Xcode 9.3 defaults. * Removes any deprecated Swift APIs. * Updates some variable names to satisfy swiftlint's constraint that names should be >= 4 characters. Please let me know if I need to change/add anything else. Thanks! :) Closes https://github.com/Instagram/IGListKit/pull/1177 Differential Revision: D8204500 Pulled By: rnystrom fbshipit-source-id: 141360acc08b179d698afa23b1d02aacca8a7434
45 lines
1.4 KiB
Swift
45 lines
1.4 KiB
Swift
/**
|
|
Copyright (c) 2016-present, Facebook, Inc. All rights reserved.
|
|
|
|
The examples provided by Facebook are for non-commercial testing and evaluation
|
|
purposes only. Facebook reserves all rights not expressly granted.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
*/
|
|
|
|
import Foundation
|
|
|
|
extension MutableCollection {
|
|
|
|
/// Shuffles the contents of this collection.
|
|
mutating func shuffle() {
|
|
guard count > 1 else { return }
|
|
|
|
for (firstUnshuffled, unshuffledCount) in zip(indices, stride(from: count, to: 1, by: -1)) {
|
|
let distance: Int = numericCast(arc4random_uniform(numericCast(unshuffledCount)))
|
|
guard distance != 0 else { continue }
|
|
|
|
let shuffleIndex = index(firstUnshuffled, offsetBy: distance)
|
|
|
|
self.swapAt(firstUnshuffled, shuffleIndex)
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
extension Sequence {
|
|
|
|
/// Returns an array with the contents of this sequence, shuffled.
|
|
var shuffled: [Iterator.Element] {
|
|
var result = Array(self)
|
|
result.shuffle()
|
|
|
|
return result
|
|
}
|
|
|
|
}
|