Skip to content

Instantly share code, notes, and snippets.

View dmlebron's full-sized avatar

David dmlebron

View GitHub Profile
private func addConstraints() {
// label constraints
textLabel.topAnchor.constraint(equalTo: view.topAnchor, constant: 50).isActive = true
textLabel.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 8).isActive = true
textLabel.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -8).isActive = true
textLabel.heightAnchor.constraint(equalToConstant: 30).isActive = true
// button constraints
showButton.topAnchor.constraint(equalTo: textLabel.bottomAnchor, constant: 16).isActive = true
showButton.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
showButton.widthAnchor.constraint(equalToConstant: 100).isActive = true
private let textLabel: UILabel = {
let label = UILabel()
label.textColor = .black
label.textAlignment = .center
label.numberOfLines = 0
label.text = "My Label"
return label
}()
private var showButton: UIButton = {
class ViewController: UIViewController {
private let textLabel: UILabel = {
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.textColor = .black
label.textAlignment = .center
label.numberOfLines = 0
label.text = "My Label"
@objc private func showViewController(sender: UIButton) {
if let secondViewController = storyboard?.instantiateViewController(withIdentifier: “secondViewController”) as? SecondViewController {
present(secondViewController, animated: true, completion: nil)
}
}
class SecondViewController: UIViewController {
private lazy var textField: UITextField = {
let txt = UITextField()
txt.returnKeyType = .done
txt.backgroundColor = .groupTableViewBackground
txt.layer.cornerRadius = 3.0
txt.translatesAutoresizingMaskIntoConstraints = false
txt.delegate = self
//
// SecondViewController.swift
// tutorial_closures
//
// Created by Dava on 5/6/17.
// Copyright © 2017 Davaur. All rights reserved.
//
import UIKit
fileprivate var textLabel: UILabel = {
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.textColor = .black
label.textAlignment = .center
label.numberOfLines = 0
label.text = "My Label"
return label
//
// CoreDataStack.swift
// altran_challenge
//
// Created by Dava on 7/7/17.
//
//
import Foundation
import CoreData
@dmlebron
dmlebron / MainViewModel.swift
Last active April 20, 2018 02:26
initial state
struct MainViewModel {
private let locationServiceType: LocationServiceType
private let apiClientType: ApiClientType
private let addressCompletion: AddressCompletion
init(locationServiceType: LocationServiceType, apiClientType: ApiClientType, addressCompletion: @escaping AddressCompletion) {
self.locationServiceType = locationServiceType
self.apiClientType = apiClientType
self.addressCompletion = addressCompletion
@dmlebron
dmlebron / MainViewModel.swift
Last active April 20, 2018 02:25
added variables for each dependency
import Foundation
struct MainViewModel {
private let locationServiceType: LocationServiceType
private let apiClientType: ApiClientType
private let addressCompletion: AddressCompletion
init(locationServiceType: LocationServiceType, apiClientType: ApiClientType, addressCompletion: @escaping AddressCompletion) {
self.locationServiceType = locationServiceType