Skip to content

Instantly share code, notes, and snippets.

View Juanpe's full-sized avatar

Juanpe Catalán Juanpe

View GitHub Profile
extension Collection where Element: UIView {
/// Returns an array containing, in order, the views of the sequence that satisfy the given predicate.
///
/// - Parameters:
/// - recursive: Boolean that indicates if filtering recursively
/// - isIncluded: A closure that takes a view of the sequence as its argument and returns a Boolean value indicating whether the view should be included in the returned array.
/// - Returns: An array of the views that isIncluded allowed.
func filter(recursive: Bool = false, _ isIncluded: (UIView) -> Bool) -> [UIView] {
return reduce(into: []) { partialResult, view in
@Juanpe
Juanpe / String+Localization.swift
Last active July 31, 2023 11:42
String extension to localize more easy way
extension String {
var localized: String {
return NSLocalizedString(self, comment: "\(self)_comment")
}
func localized(_ args: [CVarArg]) -> String {
return localized(args)
}