Forked from scotteg/SwiftArrayOfUIViewsSortInPlaceByTagExtension.swift
Last active
April 11, 2020 05:16
-
-
Save jiqqaman/65eb7723b1604a533bc67d6561e506b2 to your computer and use it in GitHub Desktop.
Sorts an array of UIViews or subclasses by tag.
This file contains 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
extension Array where Element: UIView { | |
/** | |
Sorts an array of `UIView`s or subclasses by `tag`. For example, this is useful when working with `IBOutletCollection`s, whose order of elements can be changed when manipulating the views in Interface Builder. Just tag your views in Interface Builder and then call this method on your `IBOutletCollection`s in `viewDidLoad()`. | |
- author: Scott Gardner | |
- seealso: | |
* [Source on GitHub](http://bit.ly/SortUIViewsInPlaceByTag) | |
*/ | |
mutating func sortUIViewsInPlaceByTag() { | |
sort { (left: Element, right: Element) in | |
left.tag < right.tag | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment