Skip to content

Instantly share code, notes, and snippets.

View iosdroid's full-sized avatar
🏠
Working from home

iOSDevloper iosdroid

🏠
Working from home
View GitHub Profile
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 September 10, 2024 20:41
UITableView - safe reload + section headers+footers reload without animation
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 December 18, 2023 02:31
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 January 16, 2023 19:52
Alamofire Request Error Handling - From their documentation
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)")
@santoshrajan
santoshrajan / JSONStringify.swift
Created October 12, 2014 05:36
JSON Stringify in 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 {