View TestCharsetFixedPlayground.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
View UIViewExtension.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
View 01-SecondStep-00.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)") |
View 00-StartingPoint-00.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
View QuickHashableDemo.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |
View NilCoalescing.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ########################################################## | |
// 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 |
View Some.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol P { | |
func printAhh(); | |
} | |
// Default implementation | |
extension P { | |
func printAhh() { | |
print("AHHH...") | |
} | |
} |
View Parser-0.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
<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> | |
<!-- |
View Generics-2.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
View Generics.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let aStringArray = ["Some String","AnotherString"] // Direct type assignment | |
let myFirstArray = aStringArray // Implicit type assignment, where "aStringArray" is already a String Array. | |
let myDirectArray = [String]() // Explicit empty Array definition, using brackets and an initializer. This is a common way to instantiate an Array. | |
let mySecondArray:[String] = [] // Explicit basic type definition, using brackets. This is the most common form. | |
let myThirdArray:Array<String> = [] // This is the first (explicitly defined) generic form. | |
let myFourthArray = Array<String>() // This is the second (type-assigned) generic form. | |
typealias SwiftGenericType<T> = T | |
struct SwiftGenericStruct<T> { |
NewerOlder