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
//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
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
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
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
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 |
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
let nonMutableProperty = "this content cannot change" | |
var mutableProperty = "this content can be changed" | |
mutableProperty = "changing variable content" |
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
DELEGATE METHODS CALLED WHEN OPENING APP | |
Opening app when system killed or user killed | |
didFinishLaunchingWithOptions | |
applicationDidBecomeActive | |
Opening app when backgrounded | |
applicationWillEnterForeground | |
applicationDidBecomeActive |
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
#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 |
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 | |
import Alamofire | |
class AccessTokenAdapter: RequestAdapter { | |
private let accessToken: String | |
init(accessToken: String) { | |
self.accessToken = accessToken | |
} | |