Skip to content

Instantly share code, notes, and snippets.

View jbastosneto's full-sized avatar

Jorge Bastos jbastosneto

View GitHub Profile
//
// UIAlertController+Action.swift
//
import UIKit
/**
Extension to `UIAlertController` to allow direct adding of `UIAlertAction` instances
*/
extension UIAlertController {
@ole
ole / CharacterArray.swift
Last active June 11, 2023 10:13
Two options for converting character ranges into arrays
// We can't use `Character` or `String` ranges directly because they aren't countable
// Create a countable range of ASCII values instead
let range = UInt8(ascii: "a")...UInt8(ascii: "z") // CountableClosedRange<UInt8>
// Convert ASCII codes into Character values
range.map { Character(UnicodeScalar($0)) } // Array<Character>
// → ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]