Skip to content

Instantly share code, notes, and snippets.

View Edudjr's full-sized avatar
🏠
Working from home

Eduardo Domene Junior Edudjr

🏠
Working from home
  • Mercado Livre
  • Sao Paulo
View GitHub Profile
@Edudjr
Edudjr / ViewControllerStack.swift
Created September 4, 2019 11:34
This is an example on how to create a view controller stack in swift.
import UIKit
class ViewControllerStack: UIViewController {
private var firstContainerTopAnchor: NSLayoutConstraint?
private var firstController: UIViewController?
private var controllers: [UIViewController]?
private var containerView = UIView()
init(controllers: [UIViewController]) {
self.controllers = controllers
@Edudjr
Edudjr / ObservableTestTests.swift
Last active December 17, 2019 15:20
Swift observable hanging example
//
// ObservableTestTests.swift
// ObservableTestTests
//
// Created by Eduardo Domene Junior on 01/12/19.
// Copyright © 2019 Eduardo Domene Junior. All rights reserved.
//
import XCTest
import Observable
@Edudjr
Edudjr / BottomSheetExample.swift
Last active February 5, 2021 11:42
BottomSheet with variable size fitting collapsed view
//: A UIKit based Playground for presenting user interface
// based on: https://stackoverflow.com/questions/37967555/how-can-i-mimic-the-bottom-sheet-from-the-maps-app
// This example includes an autoresizing collapsed-view.
// Clicking on "testing" will add another label, updating the collapsed-view's height.
// Click and drag the red section (BottomSheet) to update its position.
import UIKit
import PlaygroundSupport
let screenHeight: CGFloat = 400
@Edudjr
Edudjr / ViewControllerContainer.swift
Created January 29, 2021 15:36
Example of ViewController container
import UIKit
import PlaygroundSupport
let screenHeight: CGFloat = 400
let screenWidth: CGFloat = 200
class InnerViewController: UIViewController {
var stack: UIStackView = {
var label: UILabel {
let label = UILabel()
@Edudjr
Edudjr / hwnn_1.swift
Last active March 4, 2021 14:21
hwnn_1
protocol Animal {
var name: String { get }
var age: Int { get }
func makeNoise()
}
struct Dog: Animal {
let name: String
let age: Int
let myHorse = Horse(name: "Horsy", age: 5)
print(myHorse.name)
// Horsy
let animals: [Animal] = [
Dog(name: "Doggy", age: 3),
Horse(name: "Horsy", age: 5)
]
let pages = animals.map { PageDetails(animal: $0) }
let listView = ListView(pages: pages, animals: animals)
// Composition root
let animals: [Animal] = [
Dog(name: "Doggy", age: 3),
Horse(name: "Horsy", age: 5)
]
let pageDetails = PageDetails()
let vc = ListView(pageDetails: pageDetails, animals: animals)
struct AnimalReport {
let animal: Animal
func describe() {...}
}
struct AnimalSelection {
let animals: [Animal]
let animalReport: AnimalReport
func selectAnimal(_ animal: Animal) {...}
}
let animals: [Animal] = [
struct AnimalReport {
var animal: Animal?
func describe() {
guard let animal = animal else { return }
print("Animal is called \(animal.name) and is \(animal.age) years old")
}
}
struct AnimalSelection {
let animals: [Animal]