In this presentation, we're starting from Swift Generics basic examples, and diving into how we, at monday.com, took this powerful Swift feature and used it to create awesome UI/UX behaviors with generic views all over the app.
algorithms are written in terms of types to-be-specified-later that are then instantiated when needed for specific types provided as parameters.” Generic Programming @ Wikipedia !22
T) rethrows -> [T] open func decode<T>(_ type: T.Type, from data: Data) throws -> T where T : Decodable Foundations RxSwift public class Observable<Element> : ObservableType { public typealias E = Element } !23
Storing values to a local db class DBStorage<T>: Storage where T: DBSavable { ... } // An item that can be stored to a local db struct User: DBSavable { ... } !41
Storing values to a local db class DBStorage<T>: Storage where T: DBSavable { ... } // An item that can be stored to a local db struct User: DBSavable { ... } // Subclass a defined generic type final class UsersDBStorage: DBStorage<User> { } !42
Storing values to a local db class DBStorage<T>: Storage where T: DBSavable { ... } // An item that can be stored to a local db struct User: DBSavable { ... } // Subclass a defined generic type final class UsersDBStorage: DBStorage<User> { func someUsersSpecificMethod() { let values = getValues() // values: [User] } } !43
in print(option) }) menuView.configure(options: [.rename, .delete]) typealias ConfigurableCell = UITableViewCell & Configurable // after And it just works! !104 class MenuView<OptionCell>: ConfigurableView, UITableViewDataSource, UITableViewDelegate where OptionCell: ConfigurableCell { typealias OptionType = OptionCell.T // ... }
behaviors (animations, transitions, …) • Consistent UI/UX • Scalable - change the whole look in one place What’s in it for me? And will make your design team love you even more !113