Skip to content

Instantly share code, notes, and snippets.

View srdanrasic's full-sized avatar

Srđan Rašić srdanrasic

View GitHub Profile
extension ProfileViewController {
static func makeViewController(_ userService: UserService) -> ProfileViewController {
let viewController = ProfileViewController()
viewController.nameLabel.text = userService.user.name
viewController.imageView.imageUrl = userService.user.imageUrl // Assuming using an image caching libary
userService.friends.bind(to: viewController.friendsView) { cell, friend in
cell.nameLabel.text = friend.name
extension ProfileViewController {
static func makeViewController() -> ProfileViewController {
let viewController = ProfileViewController()
// ...configure viewController...
return viewController
}
}
extension ProfileViewController {
func makeLogoutButton() -> UIButton {
let button = UIButton(type: .system)
button.setTitle("Log out", for: .normal)
return button
}
}
extension ProfileViewController {
static func makeViewController(_ userService: UserService) -> ProfileViewController {
let viewController = ProfileViewController()
...
viewController.friendsView.reactive.selectedItem
.with(latestFrom: userService.friends, combine: itemAtIndex) // Take element at selected index from friends array
extension ProfileViewController {
static func makeViewController(_ userService: UserService) -> ProfileViewController {
let viewController = ProfileViewController()
viewController.nameLabel.text = userService.user.name
viewController.imageView.imageUrl = userService.user.imageUrl // Assuming using an image caching libary
userService.friends.bind(to: viewController.friendsView) { cell, friend in
cell.nameLabel.text = friend.name
extension ??? {
func makeViewController() -> ProfileViewController {
let viewController = ProfileViewController()
// ...configure viewController...
return viewController
}
}
public struct User {
public let name: String
public let imageUrl: URL
}
public class UserService {
public let user: User
public let friends: SafeSignal<[User]>
public class ProfileViewController: UIViewController {
public let nameLabel: UILabel
public let imageView: UIImageView
public let friendsView: UICollectionView
public let logoutButton: UIButton
}
import UIKit
public struct Style<View: UIView> {
public let style: (View) -> Void
public init(style: @escaping (View) -> Void) {
self.style = style
}
public class ProductView: UIView {
public let titleLabel = UILabel(style: Stylesheet.Product.title)
public let imageView = UIImageView(style: Stylesheet.Product.image)
}