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 Animal { | |
let name: String | |
let image: String | |
init (name: String, image: String) { | |
self.name = name | |
self.image = image | |
} | |
} |
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
struct Colors { | |
private init () {} | |
static let lightSalmonPink : UIColor! = UIColor(red: 248/255, green: 153/255, blue: 157/255, alpha: 1) | |
static let lightPurpleUbe : UIColor! = UIColor(red: 125/255, green: 122/255, blue: 188/255, alpha: 1) | |
static let darkGray : UIColor! = UIColor(red: 132/255, green: 146/255, blue: 166/255, alpha: 1) | |
} |
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
enum Errors : Int { | |
case Unexpected = -1 | |
case NoInternet = 1 | |
case InvalidToken = 2 | |
} |
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
//Regular function | |
func fillScreen() { | |
if let animal = self.selectedAnimal { | |
self.animalImageView.image = UIImage.init(named: animal.image) | |
self.animalNameLabel.text = animal.name.uppercased() | |
} | |
} | |
//Function with alias on parameter | |
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { |
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
extension HomeViewController : UITableViewDataSource { | |
//Métodos obrigatórios | |
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
return self.animalsArray.count | |
} | |
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
guard let cell = tableView.dequeueReusableCell(withIdentifier: homeCellIndentifier, for: indexPath) as? HomeTableViewCell else { | |
fatalError("Cannot create Home Table View Cell") | |
} |
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
override func viewDidLoad() { | |
super.viewDidLoad() | |
//TableView | |
self.tableView.delegate = self | |
self.tableView.dataSource = self | |
self.tableView.register(UITableViewCell.classForCoder(), forCellReuseIdentifier: "cell") | |
self.tableView.register(HomeTableViewCell.classForCoder(), forCellReuseIdentifier: homeCellIndentifier) | |
self.tableView.register(UINib(nibName:"HomeTableViewCell", bundle: nil), forCellReuseIdentifier: homeCellIndentifier) | |
} |
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
// MARK: - Navigation | |
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { | |
if segue.identifier == "HomeToDetailSegue" { | |
if let vc = segue.destination as? DetailViewController { | |
vc.delegate = self | |
if let animal = sender as? Animal { | |
vc.selectedAnimal = animal | |
} | |
} |
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
// MARK: - Table View | |
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { | |
tableView.deselectRow(at: indexPath, animated: true) | |
let animal = self.animalsArray[indexPath.row] | |
//programaticamente | |
let storyboard = UIStoryboard(name: "Home", bundle: nil) | |
if let vc = storyboard.instantiateViewController(withIdentifier: "DetailViewControllerID") as? DetailViewController { |
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 | |
@IBDesignable | |
class CustomView: UIView { | |
// MARK: - IBOutlets | |
@IBOutlet weak var centerImageView: UIImageView! | |
// MARK: - Init Methods |