session-ios/SignalMessaging/categories/Collection+OWS.swift
Michael Kirk 4765ed9a06 Color picker
TODO

-[x] tap to select/deselect
-[x] initially selected
-[x] integrate into conversation settings
-[x] colorPickerDelegate
-[x] translate strings
-[] reorder colors
-[x] SheetView: add top handle

Nice to have:

-[] SheetView: interactively swipe/unswipe to dismiss?
-[] preview color in bubbles
2018-09-27 13:34:23 -06:00

20 lines
550 B
Swift

//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
public extension Collection {
/// Returns the element at the specified index iff it is within bounds, otherwise nil.
public subscript (safe index: Index) -> Element? {
return indices.contains(index) ? self[index] : nil
}
}
public extension Array {
func chunked(by chunkSize: Int) -> [[Element]] {
return stride(from: 0, to: self.count, by: chunkSize).map {
Array(self[$0..<Swift.min($0 + chunkSize, self.count)])
}
}
}