Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

iOSDevloper iosdroid

🏠
Working from home
View GitHub Profile
View UserDefaultsManager.swift
import Foundation
class UserDefaultsManager {
enum Key: String {
case apiKey
case secretKey
case token
case isSignedIn
}
static let shared: UserDefaultsManager = {
return UserDefaultsManager()
@SergLam
SergLam / UITableView+Refresh.swift
Last active Oct 21, 2022
UITableView - safe reload + section headers+footers reload without animation
View UITableView+Refresh.swift
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 }
}
@cmoulton
cmoulton / URLSession Calls in Swift 4
Last active Dec 9, 2022
URLSession Calls in Swift 4
View URLSession Calls in Swift 4
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
@perlguy99
perlguy99 / Alamofire.request.error.handling.swift
Last active Jan 16, 2023
Alamofire Request Error Handling - From their documentation
View Alamofire.request.error.handling.swift
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)")
View JSONStringify.swift
// Author - Santosh Rajan
import Foundation
let jsonObject: [AnyObject] = [
["name": "John", "age": 21],
["name": "Bob", "age": 35],
]
func JSONStringify(value: AnyObject, prettyPrinted: Bool = false) -> String {