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 | |
class UserDefaultsManager { | |
enum Key: String { | |
case apiKey | |
case secretKey | |
case token | |
case isSignedIn | |
} | |
static let shared: UserDefaultsManager = { | |
return UserDefaultsManager() |
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 | |
extension UITableView { | |
func isCellVisible(section: Int, row: Int) -> Bool { | |
guard let indexes = self.indexPathsForVisibleRows else { | |
return false | |
} | |
return indexes.contains{ $0.section == section && $0.row == row } | |
} |
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
func makeGetCall() { | |
// Set up the URL request | |
let todoEndpoint: String = "https://jsonplaceholder.typicode.com/todos/1" | |
guard let url = URL(string: todoEndpoint) else { | |
print("Error: cannot create URL") | |
return | |
} | |
let urlRequest = URLRequest(url: url) | |
// set up the session |
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
Alamofire.request(urlString).responseJSON { response in | |
guard case let .failure(error) = response.result else { return } | |
if let error = error as? AFError { | |
switch error { | |
case .invalidURL(let url): | |
print("Invalid URL: \(url) - \(error.localizedDescription)") | |
case .parameterEncodingFailed(let reason): | |
print("Parameter encoding failed: \(error.localizedDescription)") | |
print("Failure Reason: \(reason)") |
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
// Author - Santosh Rajan | |
import Foundation | |
let jsonObject: [AnyObject] = [ | |
["name": "John", "age": 21], | |
["name": "Bob", "age": 35], | |
] | |
func JSONStringify(value: AnyObject, prettyPrinted: Bool = false) -> String { |