Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save scotteg/9a956f6e2d5b6e1fdd9a to your computer and use it in GitHub Desktop.
Save scotteg/9a956f6e2d5b6e1fdd9a to your computer and use it in GitHub Desktop.
Sorts an array of UIViews or subclasses by tag.
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() {
sortInPlace { (left: Element, right: Element) in
left.tag < right.tag
}
}
}
@jiqqaman
Copy link

thank you this was helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment