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 / keybase.md
Created June 2, 2019 15:40
KeyBase Proof

Keybase proof

I hereby claim:

  • I am chrismarshallny on github.
  • I am chrismarshallny (https://keybase.io/chrismarshallny) on keybase.
  • I have a public key ASA9qgqTBewdJkOVIqdYblw88MkJ0bQoBEjYQDebihAcMQo

To claim this, I am signing this object:

@ChrisMarshallNY
ChrisMarshallNY / ProtocolIssueDemo.playground
Last active April 12, 2020 19:33
This demonstrates an issue with default protocol implementations, in Swift.
// This is the little demo, at the start.
protocol A {
var thisIsRequired: String { get }
var thisIsOptional: String { get }
}
extension A {
var thisIsOptional: String { get { "" } set {} }
}
@ChrisMarshallNY
ChrisMarshallNY / Playground-0-RuntimeInformation.swift
Last active April 13, 2020 13:35
Playground Accompaniment to the Introductory Swiftwater Post
/*
PLAYGROUND 0: Runtime Information Example
©2019 Rift Valley Software. All Rights Reserved.
*/
func printInfo(_ inVal: Any) {
print("\n\tValue of Parameter:")
print("\t\tSimple Value : \(inVal)")
print("\t\tSelf : \(inVal.self)")
@ChrisMarshallNY
ChrisMarshallNY / Functions.swift
Last active April 13, 2020 13:34
Companion Playground to the Post on Functions
/*:
# FUNCTION TYPES AND PARAMETER NAMES
[This is the Apple Page on Functions](https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Functions.html)
*/
//: First, we define a function with explicitly named parameters.
func thisIsABasicFunction(with: Int, and: Int) {
print("\(with), \(and)")
}
@ChrisMarshallNY
ChrisMarshallNY / Ranges.swift
Last active April 13, 2020 13:33
Companion Playground to the Post on Ranges
//: Ranges (Open-Ended) can be empty
let rangeIsEmpty = (0..<0).isEmpty
//: ClosedRanges cannot be empty.
let closedRangeIsEmpty = (0...0).isEmpty
//: This will cause a nasty error. Uncomment to see the error.
//let downwardSpiral = 1...0
//: Same here (which makes sense).
//let downwardSpiral = 1..<0
@ChrisMarshallNY
ChrisMarshallNY / EnumsWithAssociatedValues.swift
Last active April 13, 2020 13:33
Companion Playground to the Post on Enums With Associated Values
/*
# ENUMS
Here, we'll play with associated value enums.
The scenario is an error reporting system.
We have multiple classes of errors, and, within those classes, specific errors.
We have a localized error string, and a universal error code for each specific error.
@ChrisMarshallNY
ChrisMarshallNY / ClosuresContextAndCapture.swift
Last active April 13, 2020 13:33
Companion Playground to the Closures, Context and Capture Post
var count = 0
print("\nSimple Closure (No capture list):\n")
let closure = {print("count is \(count)")}
for counter in 0..<5 {
count = counter
closure()
}
var optionalCount: Int! = 0
@ChrisMarshallNY
ChrisMarshallNY / ClosuresContextAndCapture-2.swift
Last active April 13, 2020 13:32
Companion Playground to the Closures, Contexts and Capture Post (Part 2)
var externalContextVariable: Int = 5
// These are errors
//let closure = {[inout externalContextVariable] () -> Void in
//let closure = {[var externalContextVariable] () -> Void in
let closure = {[externalContextVariable] () -> Void in
// This is an error.
// externalContextVariable = 6
print("externalContextVariable is \(externalContextVariable)")
@ChrisMarshallNY
ChrisMarshallNY / Extensions.swift
Last active April 13, 2020 13:32
Companion Playground to the Extensions Post
import CoreLocation
// Pretend this Dictionary is the result of parsing a "Localizable.strings" file.
// In this case, we are translating from Engineering to Marketing.
let g_localized_strings: [String: String] = [
"This app's infested with bugs.": "This app's loaded with features!",
"What you are asking for is impossible.": "We'll have this ready for beta-testing in a month!",
"This project is a nightmare.": "This is the project that I've been dreaming of!",
"This schedule is completely unrealistic.": "This sounds like a fascinating challenge!"
]
@ChrisMarshallNY
ChrisMarshallNY / Extensions-2.swift
Last active April 13, 2020 13:32
Companion Playground to the Second Post About Extensions
// Now, as of Swift 2, you can add "default vars and funcs" to protocol extensions:
protocol EmojiString {
var poopEmoji: String { get }
var waterEmoji: String { get }
var smileyEmoji: String { get }
}
extension EmojiString {
var poopEmoji: String { return "\u{1F4A9}" }
var waterEmoji: String { return "\u{1F30A}" }