This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// SecondViewController.swift | |
// tutorial_closures | |
// | |
// Created by Dava on 5/6/17. | |
// Copyright © 2017 Davaur. All rights reserved. | |
// | |
import UIKit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// CoreDataStack.swift | |
// altran_challenge | |
// | |
// Created by Dava on 7/7/17. | |
// | |
// | |
import Foundation | |
import CoreData |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol LocationServiceType { | |
func currentAddress(completion: @escaping (MKPlacemark?) -> ()) | |
func addressFor(postalCode: String, completion: @escaping (MKPlacemark?) -> ()) | |
} | |
protocol ApiClientType { | |
func get(url: URL, completion: @escaping ([NSDictionary]?) -> ()) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let stubService: LocationServiceType & ApiClientType = ServiceStub() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"])) | |
} | |
} |
OlderNewer