Skip to content

Instantly share code, notes, and snippets.

View chriswebb09's full-sized avatar

Christopher Webb chriswebb09

View GitHub Profile
var twoDimensionalArray: [[Int]] = [[0, 1], [2, 3]]
for i in 0..<twoDimensionalArray.count {
for n in 0..<twoDimensionalArray[i].count {
print(twoDimensionalArray[i][n])
}
}
let arrOne = [1, 2, 3, 4, 5, 6]
for i in arrOne {
print(i)
}
@chriswebb09
chriswebb09 / RemoveNodeAtIndex.swift
Created May 11, 2017 08:30
Remove Linked List Node At Index
func remove(node: Node) -> T {
let prev = node.previous
let next = node.next
if let prev = prev {
prev.next = next
} else {
head = next
}
next?.previous = prev
let arrOne = [1, 2, 3, 4, 5, 6]
func binarySearch(_ inputArray: [Int], element: Int) -> Int? {
var begin = 0
var end = inputArray.count
while begin < end {
let mid = begin + (end - begin) / 2
@chriswebb09
chriswebb09 / AppendNode.swift
Created May 11, 2017 08:24
LinkedList O(1)
func append(value: T) {
let newNode = Node(value: value)
if let lastNode = last {
newNode.previous = lastNode
lastNode.next = newNode
} else {
head = newNode
}
}
let arrOne = [1, 2, 3, 4, 5, 6]
arrOne[0]
arrOne[2]
class HashElement<T: Hashable, U> {
var key: T
var value: U?
init(key: T, value: U?) {
self.key = key
self.value = value
}
}
@chriswebb09
chriswebb09 / ImageDownloadProtocol.swift
Last active September 3, 2019 22:08
Download on Thread
import UIKit
protocol ImageDownloadProtocol {
func downloadImage(from url: URL, completion: @escaping (UIImage?) -> Void)
}
extension ImageDownloadProtocol {
func downloadImage(from url: URL, completion: @escaping (UIImage?) -> Void) {
let session = URLSession(configuration: .default)
DispatchQueue.global(qos: .background).async {
import UIKit
class ViewController: UIViewController {
let viewOne = UIView()
let viewTwo = UIView()
let intermediaryView = UIView()
let viewSuper = UIView()
override func viewDidLoad() {
import UIKit
func insertionSort(values: [Int]) {
var valuesArray = values
for i in 1...valuesArray.count - 1 {
let nextItem = valuesArray[i]
var currentIndex = i - 1
while currentIndex >= 0 && valuesArray[currentIndex] > nextItem {
valuesArray[currentIndex + 1] = valuesArray[currentIndex]