Extending UITableViewCell to preserve UIView background color when selecting the cell
This is a very strange approach for quite a few reasons.

First, the fact that this is an extension of UITableViewCell makes absolutely no sense to me.  The method is completely procedural.  It takes in an array of views (any views... from any where).  From these views, it creates an array of colors to preserve the current background color.  Then executes a function, f (which by the way, SwiftLint would never allow a single-letter variable name like this) (and you should definitely be using SwiftLint).  And function f may or may not even change the colors of any of these views.  And then we use parallel arrays, a very procedural approach, to reset these colors.

And would we even notice the color change at all?

Or is the intent here to hide the color change?



As for a more concrete review of some of the code you have, this function:


private func backgroundColors(views: [UIView]) -&gt; [UIColor?] {
    var colors = [UIColor?]()
    for view in views {
        colors.append(view.backgroundColor)
    }
    return colors
}



Could be replaced with a single line of code.

let backgroundColors = views.map { $0.backgroundColor }


But... to make our code less procedural... why don't we build a tuple array:

let viewColorPairs = views.map { ($0, $0.backgroundColor) }


And then when it comes time to reset the background colors:

for (view, color) in viewColorPairs {
    view.backgroundColor = color
}


So now we've eliminated your first two functions, and your preserveBackgroundColors function is simplified into:

func preserveBackgroundColors(views: [UIView], @noescape closure: () -&gt; Void) {
    let viewColorPairs = views.map { ($0, $0.backgroundColor) }
    closure()
    for (view, color) in viewColorPairs {
        view.backgroundColor = color
    }
}