Skip to content

Instantly share code, notes, and snippets.

View erolando's full-sized avatar
🤠

Rolando Avila erolando

🤠
View GitHub Profile
@iandundas
iandundas / theme.swift
Last active August 2, 2021 22:40
Example of creating an App Theme using structs
public protocol ThemeScheme{
var fonts: FontScheme {get}
var colours: ColourScheme {get}
}
public struct Theme: ThemeScheme{
public let fonts: FontScheme
public let colours: ColourScheme
//
// DetectBlur.swift
//
// Created by Moath_Othman on 2/9/16.
//
import Foundation
//inpired by https://gist.github.com/mortenbekditlevsen/5a0ee16b73a084ba404d
extension UIDevice {
public func MO_isBlurAvailable() -> Bool {
@gonzalezreal
gonzalezreal / ios-cell-registration-swift.md
Last active March 5, 2025 02:07
iOS Cell Registration & Reusing with Swift Protocol Extensions and Generics

iOS Cell Registration & Reusing with Swift Protocol Extensions and Generics

A common task when developing iOS apps is to register custom cell subclasses for both UITableView and UICollectionView. Well, that is if you don’t use Storyboards, of course.

Both UITableView and UICollectionView offer a similar API to register custom cell classes:

public func registerClass(cellClass: AnyClass?, forCellWithReuseIdentifier identifier: String)
public func registerNib(nib: UINib?, forCellWithReuseIdentifier identifier: String)
@benashman
benashman / Prototype.swift
Last active March 14, 2017 17:00
Swift prototype helpers (WIP)
// Generate a random color
func randomColor() -> UIColor {
let hue : CGFloat = CGFloat(arc4random() % 256) / 256 // use 256 to get full range from 0.0 to 1.0
let saturation : CGFloat = CGFloat(arc4random() % 128) / 256 + 0.5 // from 0.5 to 1.0 to stay away from white
let brightness : CGFloat = CGFloat(arc4random() % 128) / 256 + 0.5 // from 0.5 to 1.0 to stay away from black
return UIColor(hue: hue, saturation: saturation, brightness: brightness, alpha: 1)
}
// Execute block after delay
@hishma
hishma / logPretty.swift
Created December 17, 2015 00:08
Debug like a caveman in swift
func logPretty(message: String? = nil, file: String = __FILE__, line: UInt = __LINE__, function: StaticString = __FUNCTION__) {
var pretty = "\((file as NSString).lastPathComponent)(\(line)) : \(function)"
if let message = message where !message.isEmpty {
pretty += " ☞ \(message)"
}
print(pretty)
}
@KentarouKanno
KentarouKanno / Pop or Dismiss.swift
Last active September 23, 2021 13:22
UINavigationController Pop or UIViewController dismiss
// Check UINavigationController Pop or UIViewController dismiss
override func viewDidDisappear(animated: Bool) {
super.viewDidDisappear(animated)
let vcs = self.navigationController?.viewControllers
if ((vcs?.contains(self)) == nil) {
print("UINavigationController Pop")
} else {
@algal
algal / FontUtils.swift
Last active January 12, 2018 18:43
Type-safe font initiazer
//
// MARK: Font utilities
//
enum FontFamily : String {
case HelveticaNeue = "Helvetica Neue"
case MontSerrat = "Montserrat"
}
enum FontWeight {
@Tokuriku
Tokuriku / Count lines of code in Xcode project
Last active June 30, 2024 21:09 — forked from ccabanero/Count lines of code in Xcode project
Count lines of code in SWIFT Xcode project
1. Open Terminal
2. cd to your Xcode project
3. Execute the following when inside your target project:
find . -name "*.swift" -print0 | xargs -0 wc -l
@peerax
peerax / ios sqlite
Created December 15, 2014 15:33
SQlite ios Set get version
PRAGMA user_version;//Get
PRAGMA user_version = 2; //Set
extension UIImage {
public func imageRotatedByDegrees(degrees: CGFloat) -> UIImage {
let radiansToDegrees: (CGFloat) -> CGFloat = {
return $0 * (180.0 / CGFloat(M_PI))
}
let degreesToRadians: (CGFloat) -> CGFloat = {
return $0 / (180.0 * CGFloat(M_PI))
}
// calculate the size of the rotated view's containing box for our drawing space