You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
func configure<T>(
_ value:T,
using closure:(inoutT)throws->Void)rethrows->T{varvalue= value
tryclosure(&value)return value
}
Extending optionals in Swift
extensionOptionalwhere Wrapped:Collection{varisNilOrEmpty:Bool{returnself?.isEmpty ??true}}extensionOptional{func matching(_ predicate:(Wrapped)->Bool)->Wrapped?{guardlet value =selfelse{returnnil}guardpredicate(value)else{returnnil}return value
}}
Passing key paths as functions
structMovie{varname:StringvarisFavorite:Bool...}letmovies:[Movie]=loadMovies()
// Equivalent to movies.map { $0.name }
letmovieNames= movies.map(\.name)
// Equivalent to movies.filter { $0.isFavorite }
letfavoriteMovies= movies.filter(\.isFavorite)