Last active
March 3, 2020 13:23
-
-
Save dnedrow/7c335853831496194ef26fe477c2e27b to your computer and use it in GitHub Desktop.
Array utility routines.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Array+Extensions.swift | |
| // Attribution 4.0 International (CC 4.0), see bottom for license details. | |
| import Foundation | |
| extension Array where Element == String? { | |
| // converts an array of optional accessibility labels to a single accessibility label that can be set on an accessibility element | |
| var convertedToAccessibilityLabel: String { | |
| return self.compactMap { $0 }.joined(separator: ", ") | |
| } | |
| } | |
| extension Array { | |
| public mutating func rearrange(fromIndex: Int?, toIndex: Int) { | |
| guard let from = fromIndex else { | |
| return | |
| } | |
| let element = self.remove(at: from) | |
| self.insert(element, at: toIndex) | |
| } | |
| } | |
| // This work is licensed under Attribution 4.0 International (CC 4.0) | |
| // You are free to: | |
| // Share — copy and redistribute the material in any medium or format | |
| // Adapt — remix, transform, and build upon the material | |
| // for any purpose, even commercially. | |
| // | |
| // This license is acceptable for Free Cultural Works. | |
| // The licensor cannot revoke these freedoms as long as you follow the license terms. | |
| // See https://creativecommons.org/licenses/by/4.0/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment