Skip to content

Instantly share code, notes, and snippets.

View yabenatti's full-sized avatar

Yasmin Benatti yabenatti

  • Sweden
View GitHub Profile
@yabenatti
yabenatti / TableViewTutorial01.swift
Created November 12, 2017 12:44
TableViewTutorial01
import UIKit
class ViewController: UIViewController {
// MARK: - IBOutlets
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
@yabenatti
yabenatti / DelegateTutorialSecondViewController.swift
Created November 10, 2017 16:30
DelegateTutorialSecondViewController
import UIKit
protocol SecondViewControllerProtocol {
func didDoSomethingOnSecondViewController(message: String)
}
class SecondViewController: UIViewController {
//MARK: - Variables
var delegate: SecondViewControllerProtocol?
@yabenatti
yabenatti / DelegateTutorialFirstViewController.swift
Created November 10, 2017 16:26
DelegateTutorialFirstViewController
import UIKit
class FirstViewController: UIViewController, SecondViewControllerProtocol {
// MARK: - Navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "FirstToSecondSegue" {
if let vc = segue.destination as? SecondViewControllerProtocol {
vc.delegate = self
}
@yabenatti
yabenatti / UIAlertControllerSelectedAnimal.swift
Created November 10, 2017 16:21
UIAlertControllerSelectedAnimal
func selectedTheAnimal(animal: Animal) {
let alert = UIAlertController(title: animal.name.uppercased(), message: "Selected the: \(animal.name)", preferredStyle: .alert)
let action = UIAlertAction(title: "OK", style: .cancel, handler: nil);
alert.addAction(action)
self.present(alert, animated: true, completion: nil)
}
@yabenatti
yabenatti / HideKeyboard.swift
Created November 10, 2017 16:20
HideKeyboard
// MARK: - Keyboard
@IBAction func hideKeyboard(_ sender: Any) {
self.view.endEditing(true)
}
@yabenatti
yabenatti / BarButtonItem.swift
Created November 10, 2017 16:18
BarButtonItem
self.navigationItem.setRightBarButton(UIBarButtonItem(barButtonSystemItem: .save, target: self, action: #selector(saveProfile)), animated: true)
@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 / 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 / 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 / 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)
}