Skip to content

Instantly share code, notes, and snippets.

Eliasz Sawicki Eluss

Block or report user

Report or block Eluss

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Eluss
Eluss / lenses.swift
Created Jun 27, 2019
Kickstart your app with lenses
View lenses.swift
struct Dog {
var name: String
}
struct Person {
var name: String
var age: Int
var dog: Dog
}
View PersonViewModel.swift
class DetailedPersonViewModel: PersonViewModel {
var title: String
var birthday: String
var dateFormatter = DateFormatter()
init(person: Person) {
title = person.firstName + " " + person.lastName
dateFormatter.dateStyle = .short
birthday = dateFormatter.string(from: person.birthday)
View PersonView2.swift
protocol PersonViewModel {
var title: String {get}
var birthday: String {get}
func doSomeWork()
}
class PersonView: UIView {
private var titleLabel: UILabel!
private var birthdayLabel: UILabel!
private var workButton: UIButton!
View PersonView1.swift
class PersonView: UIView {
private var titleLabel: UILabel!
private var birthdayLabel: UILabel!
private var workButton: UIButton!
private var person: Person
private var dateFormatter = DateFormatter()
View personModel.swift
struct Person {
 var firstName: String
 var lastName: String
 var birthday: Date
}
View MoveAnchor.swift
var buttonLeftConstraint: NSLayoutConstraint?
func pureLayout() {
buttonLeftConstraint = animateButton.autoPinEdge(toSuperviewEdge: .left, withInset: 20)
animateButton.autoPinEdge(toSuperviewEdge: .top, withInset: 50)
animateButton.autoSetDimensions(to: CGSize(width: 100, height: 100))
}
func animate() {
UIView.animate(withDuration: 1) {
View ScrollWithSurpriseAnchor.swift
func pureLayout() {
scrollView.autoPinEdgesToSuperviewEdges(with: .zero)
scrollView.autoPinEdge(.bottom, to: .bottom, of: longer, withOffset: 20)
box.autoPinEdge(toSuperviewEdge: .top, withInset: 150)
box.autoAlignAxis(toSuperviewAxis: .vertical)
box.autoSetDimensions(to: CGSize(width: 100, height: 100))
circle.autoPinEdge(.bottom, to: .bottom, of: self.view, withOffset: -20, relation: .lessThanOrEqual)
circle.autoPinEdge(.bottom, to: .top, of: longer, withOffset: -20, relation: .lessThanOrEqual)
View ScrollViewAnchor.swift
func pureLayout() {
scrollView.autoPinEdgesToSuperviewEdges(with: .zero)
scrollView.autoPinEdge(.bottom, to: .bottom, of: longer, withOffset: 20)
box.autoPinEdge(toSuperviewEdge: .top, withInset: 50)
box.autoPinEdge(.left, to: .left, of: self.view, withOffset: 20)
box.autoSetDimensions(to: CGSize(width: 100, height: 100))
circle.autoPinEdge(.top, to: .top, of: box)
circle.autoPinEdge(.right, to: .right, of: self.view, withOffset: -20)
View SimpleAnchor.swift
func pureLayout() {
box.autoPinEdge(toSuperviewEdge: .top, withInset: 50)
box.autoPinEdge(toSuperviewEdge: .left, withInset: 20)
box.autoSetDimensions(to: CGSize(width: 100, height: 100))
circle.autoPinEdge(.top, to: .top, of: box)
circle.autoPinEdge(toSuperviewEdge: .right, withInset: 20)
circle.autoSetDimensions(to: CGSize(width: 100, height: 100))
longer.autoPinEdge(toSuperviewEdge: .left, withInset: 20)
View UpdateConstraints.swift
var buttonLeftConstraint: NSLayoutConstraint?
func pureLayout() {
buttonLeftConstraint = animateButton.autoPinEdge(toSuperviewEdge: .left, withInset: 20)
animateButton.autoPinEdge(toSuperviewEdge: .top, withInset: 50)
animateButton.autoSetDimensions(to: CGSize(width: 100, height: 100))
}
func animate() {
UIView.animate(withDuration: 1) {
You can’t perform that action at this time.