Skip to content

Instantly share code, notes, and snippets.

@dnedrow
Last active March 3, 2020 13:23
Show Gist options
  • Select an option

  • Save dnedrow/7c335853831496194ef26fe477c2e27b to your computer and use it in GitHub Desktop.

Select an option

Save dnedrow/7c335853831496194ef26fe477c2e27b to your computer and use it in GitHub Desktop.
Array utility routines.
// 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