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
//
// 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 / Protocols.swift
Last active April 19, 2018 20:25
added dependencies protocols
protocol LocationServiceType {
func currentAddress(completion: @escaping (MKPlacemark?) -> ())
func addressFor(postalCode: String, completion: @escaping (MKPlacemark?) -> ())
}
protocol ApiClientType {
func get(url: URL, completion: @escaping ([NSDictionary]?) -> ())
}
typealias AddressCompletion = (String) -> ()
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
@dmlebron
dmlebron / MainView.swift
Last active April 19, 2018 21:15
view model initial refactoring
class MainView: UIViewController, UITextFieldDelegate, UITableViewDataSource {
@IBOutlet weak var topView: UIView!
@IBOutlet weak var addressLabel: UILabel!
@IBOutlet weak var searchText: UITextField!
@IBOutlet weak var searchButton: UIButton!
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var searchStackView: UIStackView!
private var viewModel: MainViewModel!
let stubService: LocationServiceType & ApiClientType = ServiceStub()
class MainViewModelTests: XCTestCase {
let stubService: LocationServiceType & ApiClientType = ServiceStub()
func testUpdateCurrentAddress() {
let viewModel = MainViewModel(locationServiceType: stubService, apiClientType: stubService, addressCompletion: { address in
expect(address).to(equal(DummyData.fullAddress))
})
viewModel.updateCurrentAddress()
func testFetchJobsAroundPostalCode() {
let viewModel = MainViewModel(locationServiceType: stubService, apiClientType: stubService, addressCompletion: { address in
expect(address).to(equal(DummyData.Location.fullAddress))
})
viewModel.fetchJobsAround(postalCode: DummyData.Location.postalCode) { (response) in
let responseTitle = response!.first!["title"] as! String
expect(responseTitle).to(equal(DummyData.Api.response["title"]))
}
}