Skip to content

Instantly share code, notes, and snippets.

@nickarthur
nickarthur / LockingWithSwiftAndGCD.swift
Created February 19, 2019 10:14 — forked from dr2050/LockingWithSwiftAndGCD.swift
Locking Demo with GCD and Swift (Playground)
import Foundation
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
// CHANGE THIS TO TRUE FOR the lock queue to be used
let useLocks = false
var counter : Int = 0
@nickarthur
nickarthur / access1.swift
Created February 5, 2019 22:01 — forked from mildocjr/access1.swift
access-1
public class myClass {
}
// the public keyword defines the access control for this class
@nickarthur
nickarthur / iflet5.swift
Created February 5, 2019 21:56 — forked from mildocjr/iflet5.swift
if-let-5
if let actualInteger = possibleInteger,
let actualDouble = actualInteger as? Double {
// do stuff with actualInteger
// or actualDouble
}
@nickarthur
nickarthur / iflet4.swift
Created February 5, 2019 21:55 — forked from mildocjr/iflet4.swift
if-let-4
if let acutualInteger = possibleInteger,
var actualString = possibleString {
// do stuff
}
@nickarthur
nickarthur / iflet3.swift
Created February 5, 2019 21:49 — forked from mildocjr/iflet3.swift
if-let-3
func add(firstPossibleInteger: Int?, secondPossibleInteger: Int?) -> Int? {
guard let firstNumber = firstPossibleInteger,
let secondNumber = secondPossibleNumber
else { return nil } // or 0 if you want to return a
// non-optional value
return (firstNumber + secondNumber)
}
@nickarthur
nickarthur / iflet2.swift
Created February 5, 2019 21:47 — forked from mildocjr/iflet2.swift
if-let-2
if let actualDouble = possibleDouble {
// do stuff with actualDouble
}
@nickarthur
nickarthur / iflet1.swift
Created February 5, 2019 21:39 — forked from mildocjr/iflet1.swift
if-let-1
if let actualInteger = possibleInteger as? Int {
// do stuff with actual integer
print(actualInteger) // prints 3
print(possibleInteger) // prints Optional(3)
// actualInteger's scope ends here
}
@nickarthur
nickarthur / typecast5.swift
Created February 5, 2019 21:23 — forked from mildocjr/typecast5.swift
type-cast-5
class CustomTableViewCell: UITableViewCell {
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var title: UILabel!
@IBOutlet weak var subtitle: UILabel!
}
class TableView: UITableView {
func tableView(_ tableView: UITableView,
cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(with: identifier)
@nickarthur
nickarthur / typecast4.swift
Created February 5, 2019 21:21 — forked from mildocjr/typecast4.swift
type-cast-4
var integerValue = 42
var stringValue = String(describing: 42)
var doubleValue = integerValue as! Double
var floatValue = Int(stringValue) as? Float
var array: [String] = ["eggs", "bacon", "ham", "cheese"]
let arrayCount = Double(array.count as? String)
var numArray: [Int] = [1, 2, 3, 4, 5]
@nickarthur
nickarthur / typecast3.swift
Created February 5, 2019 21:15 — forked from mildocjr/typecast3.swift
type-cast-3
var integerValue = 42
var stringValue = integerValue as? String