Skip to content

Instantly share code, notes, and snippets.

View yabenatti's full-sized avatar

Yasmin Benatti yabenatti

  • Sweden
View GitHub Profile
@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 / 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 / MiniCursoIFSPSwiftEnum.swift
Created November 10, 2017 11:46
MiniCursoIFSPSwiftEnum
enum Errors : Int {
case Unexpected = -1
case NoInternet = 1
case InvalidToken = 2
}
@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 / 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 / MiniCursoIFSPSwiftOptionals.swift
Created November 10, 2017 00:19
MiniCursoIFSPSwiftOptionals
var optionalString: String? = nil
if let unwrappedOptionalWithIf = optionalString {
print("Use \(unwrappedOptionalWithIf) here")
}
func printString(string: String?) {
guard let unwrappedOptionalWithGuard = optionalString else {
print("Treat error")
return
@yabenatti
yabenatti / MiniCursoIFSPSwiftProperties.swift
Created November 9, 2017 23:59
MiniCursoIFSPSwiftProperties
let nonMutableProperty = "this content cannot change"
var mutableProperty = "this content can be changed"
mutableProperty = "changing variable content"
@yabenatti
yabenatti / .txt
Created August 23, 2017 17:40
App Delegate Methods When Opening the App
DELEGATE METHODS CALLED WHEN OPENING APP
Opening app when system killed or user killed
didFinishLaunchingWithOptions
applicationDidBecomeActive
Opening app when backgrounded
applicationWillEnterForeground
applicationDidBecomeActive
@yabenatti
yabenatti / SaveUserDefault.m
Created June 20, 2017 11:53
Saving content to UserDefault
#pragma mark - User Defaults
//Saves information on cache
+ (void)saveToUserDefault:(NSObject*)objectToSave withKey:(NSString*)key {
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:objectToSave forKey:key];
[userDefaults synchronize];
}
//Retrieves information from cache
@yabenatti
yabenatti / AccessTokenAdapter.swift
Last active July 11, 2017 12:48
Alamofire Manager
import Foundation
import Alamofire
class AccessTokenAdapter: RequestAdapter {
private let accessToken: String
init(accessToken: String) {
self.accessToken = accessToken
}