Skip to content

Instantly share code, notes, and snippets.

@thiagobutignon
Last active November 4, 2019 22:53
Show Gist options
  • Save thiagobutignon/503abb9028dff21e881c82c5bcabfc7b to your computer and use it in GitHub Desktop.
Save thiagobutignon/503abb9028dff21e881c82c5bcabfc7b to your computer and use it in GitHub Desktop.
import Foundation
protocol CriarUsuarioPresenter: class {
func success()
func failed()
}
class CriarUsuario {
var delegate: CriarUsuarioPresenter?
let api: API = API()
func retornaNomeDoUsuario(user: User) {
let name:String = api.userSignUp(user: user)
if name == "Thiago" {
self.delegate?.success()
} else {
self.delegate?.failed()
}
}
}
import Foundation
//Requisição pro localhost:3333/signIn utilizando model user
protocol ContratoAPI {
func userSignUp(user: User) -> String
// Clojure.... completion HTTP 200, 300, 400, 500...
func userSingIn()
func userLogout()
}
class API: ContratoAPI {
func userSignUp(user: User) -> String {
return user.name
}
func userSignUp(user: User) {
}
func userSingIn() {
}
func userLogout() {
}
}
import Foundation
struct User {
let name: String
let lastName: String?
let email: String?
let password: String
}
import UIKit
class ViewController: UIViewController {
var dataprovider: CriarUsuario = CriarUsuario()
let user: User = User(name: "Joao", lastName: "", email: "", password: "")
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.dataprovider.delegate = self
dataprovider.retornaNomeDoUsuario(user: user)
}
func label(name: String) {
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 21))
label.center = CGPoint(x: 160, y: 285)
label.textAlignment = .center
label.text = name
self.view.addSubview(label)
}
}
extension ViewController: CriarUsuarioPresenter {
func success() {
print("\(self.user.name) é foda!")
self.label(name: self.user.name)
viewDidAppear(true)
}
func failed() {
print("\(self.user.name) é bonitão!")
self.label(name: self.user.name)
}
}
import UIKit
class ViewController: UIViewController {
var dataprovider: CriarUsuario = CriarUsuario()
let user: User = User(name: "Joao", lastName: "", email: "", password: "")
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.dataprovider.delegate = self
dataprovider.retornaNomeDoUsuario(user: user)
}
func label(name: String) {
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 21))
label.center = CGPoint(x: 160, y: 285)
label.textAlignment = .center
label.text = name
self.view.addSubview(label)
}
}
extension ViewController: CriarUsuarioPresenter {
func success() {
print("\(self.user.name) é foda!")
self.label(name: self.user.name)
viewDidAppear(true)
}
func failed() {
print("\(self.user.name) é bonitão!")
self.label(name: self.user.name)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment