Skip to content

Instantly share code, notes, and snippets.

View erolando's full-sized avatar
🤠

Rolando Avila erolando

🤠
View GitHub Profile
// Basic.swift
extension Notification.Name {
func post(object:Any? = nil, userInfo:[AnyHashable: Any]? = nil) {
NotificationCenter.default.post(self, object: object, userInfo: userInfo)
}
}
// DataModel.swift
extension Notification.Name {
static let AccountBalanceUpdated = Notification.Name("accountBalanceUpdated")
@tadija
tadija / FontNames-iOS-17.4.swift
Last active January 11, 2025 00:45
iOS - All Font Names
/*
*** Academy Engraved LET ***
AcademyEngravedLetPlain
---------------------
*** Al Nile ***
AlNile
AlNile-Bold
---------------------
*** American Typewriter ***
AmericanTypewriter
@Gurdeep0602
Gurdeep0602 / AppStoryboard.swift
Last active April 2, 2024 09:54
AppStoryboard enumeration
//
// AppStoryboards.swift
// AppStoryboards
//
// Created by Gurdeep on 15/12/16.
// Copyright © 2016 Gurdeep. All rights reserved.
//
import Foundation
import UIKit
@cmoulton
cmoulton / Custom HTTP Headers with Swift and Alamofire.swift
Last active July 15, 2022 12:37
Custom HTTP Headers with Swift 3 or 4 and Alamofire 4.0-4.7: See https://grokswift.com/custom-headers-alamofire4-swift3/ for explanations
// MARK: - Adding a header to a single request
func doRequestWithHeaders1() {
let headers: HTTPHeaders = [
"X-Mashape-Key": MY_API_KEY,
"Accept": "application/json"
]
Alamofire.request("https://mashape-community-urban-dictionary.p.mashape.com/define?term=smh", headers: headers)
.responseJSON { response in
debugPrint(response)
@AlexanderZ-aFrogleap
AlexanderZ-aFrogleap / SectionedTableViewAdapter.swift
Created October 15, 2016 20:12
Generic UITableView adapter with sections
//: Playground - noun: a place where people can play
import UIKit
protocol SectionModel {
var count: Int { get }
func cell(at: Int) -> UITableViewCell
func selected(at: Int)
}
exec > /tmp/${PROJECT_NAME}_archive.log 2>&1
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
if [ "true" == ${ALREADYINVOKED:-false} ]
then
echo "RECURSION: Detected, stopping"
else
export ALREADYINVOKED="true"
@cmoulton
cmoulton / URLSession Calls in Swift 3.0.1
Last active November 4, 2022 00:29
URLSession Calls in Swift 3.0.1
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
@jonathanduty
jonathanduty / OnMain.swift
Created August 16, 2016 19:12
Neato OnMain swift keyword.
import Foundation
func onMain(closure: () -> ()) {
if NSThread.isMainThread() {
closure()
}
else {
dispatch_async(dispatch_get_main_queue(), closure)
}
}
@DTHENG
DTHENG / UIColor+random.swift
Last active May 18, 2017 23:53
Random color from UIColor
import UIKit
extension UIColor {
static func random() -> UIColor {
switch (arc4random_uniform(15)) {
case 0:
return UIColor.blackColor()
case 1:
return UIColor.darkGrayColor()
@kos9kus
kos9kus / NSURLErrorDomain.h
Last active October 25, 2024 05:04
URL Loading System Error Codes
These values are returned as the error code property of an NSError object with the domain “NSURLErrorDomain”.
Declaration
SWIFT
var NSURLErrorUnknown: Int { get }
var NSURLErrorCancelled: Int { get }
var NSURLErrorBadURL: Int { get }
var NSURLErrorTimedOut: Int { get }
var NSURLErrorUnsupportedURL: Int { get }
var NSURLErrorCannotFindHost: Int { get }