Last active
November 4, 2019 22:53
-
-
Save thiagobutignon/503abb9028dff21e881c82c5bcabfc7b to your computer and use it in GitHub Desktop.
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
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() | |
} | |
} | |
} |
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
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() { | |
} | |
} |
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
import Foundation | |
struct User { | |
let name: String | |
let lastName: String? | |
let email: String? | |
let password: String | |
} |
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
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) | |
} | |
} |
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
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