Skip to content

Instantly share code, notes, and snippets.

View ChrisMarshallNY's full-sized avatar
🐲
Developing in Swift, on Long Island, NY

Chris Marshall ChrisMarshallNY

🐲
Developing in Swift, on Long Island, NY
View GitHub Profile
@ChrisMarshallNY
ChrisMarshallNY / RVS_FadeAnimator.swift
Last active July 14, 2022 17:57
A UIViewController Fade Animator
import UIKit
/* ###################################################################################################################################### */
// MARK: Fade Transition Animator
/* ###################################################################################################################################### */
/**
This allows us to do a fade between two screens.
It was inspired by [this Medium post](https://medium.com/@ludvigeriksson/custom-interactive-uinavigationcontroller-transition-animations-in-swift-4-a4b5e0cefb1e)
*/
open class RVS_FadeAnimator: NSObject, UIViewControllerAnimatedTransitioning {
/* ################################################################## */
@ChrisMarshallNY
ChrisMarshallNY / TestCharsetFixedPlayground.swift
Last active July 13, 2020 12:11
Strange Character Set Comparison Issue
import Foundation
public extension StringProtocol {
func containsOneOfThese(_ inCharacterset: CharacterSet) -> Bool {
self.contains { (char) in
char.unicodeScalars.contains { (scalar) in inCharacterset.contains(scalar) }
}
}
func containsOneOfThese(_ inString: String) -> Bool {
@ChrisMarshallNY
ChrisMarshallNY / UIViewExtension.swift
Created June 1, 2020 15:50
UIView Extension to Add An Auto-Layout SubView With Equal All-Around Constraints (Fill)
extension UIView {
/* ################################################################## */
/**
This allows us to add a subview, and set it up with auto-layout constraints to fill the superview.
- parameter inSubview: The subview we want to add.
*/
func addContainedView(_ inSubView: UIView) {
addSubview(inSubView)
@ChrisMarshallNY
ChrisMarshallNY / 01-SecondStep-00.swift
Last active July 20, 2020 22:34
Companion Gists to the Introduction to Core Bluetooth Class
extension ITCB_SDK_Device_Peripheral: CBPeripheralDelegate {
public func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) {
if let error = error {
print("Encountered an error \(error) for the Peripheral \(peripheral.name ?? "ERROR")")
owner?._sendErrorMessageToAllObservers(error: ITCB_Errors.coreBluetooth(error))
return
}
print("Successfully Discovered \(peripheral.services?.count ?? 0) Services for \(peripheral.name ?? "ERROR").")
peripheral.services?.forEach {
print("Discovered Service: \($0.uuid.uuidString)")
@ChrisMarshallNY
ChrisMarshallNY / 00-StartingPoint-00.swift
Last active June 12, 2020 17:25
Companion Gists to the Introduction to Core Bluetooth Class
extension ITCB_SDK_Central {
override var _managerInstance: Any! {
get {
if super._managerInstance == nil {
print("Creating A new instance of CBCentralManager.")
super._managerInstance = CBCentralManager(delegate: self, queue: nil)
}
return super._managerInstance
}
struct A<T: Hashable>: Hashable {
static func == (lhs: A<T>, rhs: A<T>) -> Bool { lhs.tVar == rhs.tVar }
let tVar: T
init(_ inVat: T) {
tVar = inVat
}
}
@ChrisMarshallNY
ChrisMarshallNY / NilCoalescing.swift
Created April 13, 2020 13:48
Companion Playground to the Nil-Coalescing Operator Post
// ##########################################################
// SET UP FOUR CONSTANT ARRAYS OF INT
// ##########################################################
let array1 = [0,1,2,3,4]
let array2 = [5,6,7,8,9]
let array3 = [10,11,12,13,14]
let array4 = [15,16,17,18,19]
// ##########################################################
// WE USE AN IMPLICITLY UNRWAPPED OPTIONAL
@ChrisMarshallNY
ChrisMarshallNY / Some.swift
Created April 13, 2020 13:46
Companion Playground to the "Some" People Say Post
protocol P {
func printAhh();
}
// Default implementation
extension P {
func printAhh() {
print("AHHH...")
}
}
@ChrisMarshallNY
ChrisMarshallNY / Parser-0.swift
Created April 13, 2020 13:42
Companion Repos to the Series on Writing A Parser in Swift
/*
<containerElement>
<arrayElement>Element Value 01</arrayElement>
<arrayElement>Element Value 02</arrayElement>
<arrayElement>Element Value 03</arrayElement>
<arrayElement>Element Value 04</arrayElement>
<arrayElement>Element Value 05</arrayElement>
</containerElement>
<!--
@ChrisMarshallNY
ChrisMarshallNY / Generics-2.swift
Created April 13, 2020 13:37
Companion Playground to the Second Post on Generics
// This is a completely generic protocol. You can use any type for "T".
protocol GenericBaseProtocol {
associatedtype T
var myProperty: T {get set}
init(_ myProperty: T )
}
// You can declare both Comparable and non-Comparable types with this protocol.
// This is Comparable