Skip to content

Instantly share code, notes, and snippets.

View yabenatti's full-sized avatar

Yasmin Benatti yabenatti

  • Sweden
View GitHub Profile
@yabenatti
yabenatti / MiniCursoIFSPSwiftClass.swift
Created November 10, 2017 11:44
MiniCursoIFSPSwiftClass
class Animal {
let name: String
let image: String
init (name: String, image: String) {
self.name = name
self.image = image
}
}
@yabenatti
yabenatti / MiniCursoIFSPSwiftStruct.swift
Created November 10, 2017 11:45
MiniCursoIFSPSwiftStructAsNamespace
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)
}
@yabenatti
yabenatti / MiniCursoIFSPSwiftEnum.swift
Created November 10, 2017 11:46
MiniCursoIFSPSwiftEnum
enum Errors : Int {
case Unexpected = -1
case NoInternet = 1
case InvalidToken = 2
}
@yabenatti
yabenatti / MiniCursoIFSPSwiftFunctions.swift
Last active November 10, 2017 11:52
MiniCursoIFSPSwiftFunctions
//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) {
@yabenatti
yabenatti / MiniCursoIFSPSwiftTableViewDataSource.swift
Created November 10, 2017 12:22
MiniCursoIFSPSwiftTableViewDataSource
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")
}
@yabenatti
yabenatti / MiniCursoIFSPSwiftTableViewRegisterCells.swift
Created November 10, 2017 12:46
MiniCursoIFSPSwiftTableViewRegisterCells
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)
}
@yabenatti
yabenatti / MiniCursoIFSPSwiftSegue.swift
Created November 10, 2017 12:51
MiniCursoIFSPSwiftSegue
// 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
}
}
@yabenatti
yabenatti / MiniCursoIFSPSwiftSegueProgramaticamente.swift
Created November 10, 2017 12:52
MiniCursoIFSPSwiftSegueProgramaticamente
// 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 {
@yabenatti
yabenatti / CustomView.swift
Created November 10, 2017 16:17
CustomView
import UIKit
@IBDesignable
class CustomView: UIView {
// MARK: - IBOutlets
@IBOutlet weak var centerImageView: UIImageView!
// MARK: - Init Methods
@yabenatti
yabenatti / BarButtonItem.swift
Created November 10, 2017 16:18
BarButtonItem
self.navigationItem.setRightBarButton(UIBarButtonItem(barButtonSystemItem: .save, target: self, action: #selector(saveProfile)), animated: true)