Skip to content

Instantly share code, notes, and snippets.

@pablogm
pablogm / Array+Utils.swift
Last active February 11, 2018 09:31
Swift Array Utils: append an element if it doesn't exist, retrieve the latest element, ...
//
// Array+Utils.swift
// Swift Utils
//
import Foundation
extension Array where Element: Hashable {
mutating func filterAppend(newElement: Element) {
@pablogm
pablogm / UIApplication+Utils.swift
Last active May 30, 2018 09:54
Swift UIApplication utils: Get the top view controller
//
// UIApplication+Utils.swift
// Swift Utils
//
import Foundation
extension UIApplication {
class func topViewController(base: UIViewController? = (UIApplication.sharedApplication().delegate as! AppDelegate).window?.rootViewController) -> UIViewController? {
@pablogm
pablogm / UIViewController+Utils.swift
Last active September 13, 2016 19:03
Swift UIViewController utils: custom status bar background color, popup alert message, ...
//
// UIViewController+StatusBar.swift
// Swift Extensions
//
import Foundation
import UIKit
/// Custom status bar background color on UIViewController
extension UIViewController {
@pablogm
pablogm / NSDate+Utils.swift
Last active July 22, 2017 18:53
Swift NSDate utils: Get date by adding / subtracting days from now, date at midnight, ...
//
// NSDate+Utils.swift
// Swift Extensions
//
import Foundation
import UIKit
extension NSDate {
class func dateByAddingDays(days: Int) -> NSDate {
@pablogm
pablogm / String+Utils.swift
Last active November 26, 2021 08:50
Swift String extensions: localized strings, html to attributed string, check if valid email, generate random string, ...
//
// String+Localizable.swift
// Swift extensions
//
import Foundation
import UIKit
// MARK: Localized
@pablogm
pablogm / UIColor+Hex.swift
Last active November 24, 2015 11:08
Swift extension to get UIColor from it hex representation
//
// UIColor+Hex.swift
// Swift extensions
//
import Foundation
import UIKit
enum ColorComponentError: ErrorType {
case InvalidRedComponent
@pablogm
pablogm / NSThread+blocks.swift
Last active October 10, 2021 06:45
Swift extension to add some methods to the NSThread class to run a block on any thread you have a reference to.
//
// NSThread+blocks.swift
// Swift extensions
//
import Foundation
public typealias Block = @convention(block) () -> Void
extension NSThread {