extension Dictionary {
func map<U> (transform: Value -> U) -> Dictionary<Key, U> {
var result = Dictionary<Key, U>()
for (key, value) in self {
result[key] = transform(value)
}
return result
}
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
func someFunction(a: Int, _ b: Int) { | |
print(a, b) | |
} | |
someFunction(1, 2) |
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
// Original Solution - Excerpt From: Wayne Bishop. “SWIFT ALGORITHMS & DATA STRUCTURES.” | |
func insertionSort(var numberList: Array<Int>) -> Array<Int> { | |
var y, key : Int | |
for x in 0..<numberList.count { | |
key = numberList[x] | |
for (y = x; y > -1; y--) { |
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
private func handleContentChange() { | |
let tableViewHeight = CGFloat(subViewModel.count()) * rowHeight | |
let contentHeight = standardPadding + segmentedControlHeight.constant + standardPadding + tableViewHeight + standardPadding + openButtonHeight.constant + standardPadding | |
dispatch_async(dispatch_get_main_queue()) { | |
self.tableView.reloadData() | |
self.preferredContentSize.height = contentHeight | |
} |
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 UIKit | |
var array = [AnyObject]() | |
array.append(1) | |
array.append(2.0) | |
array.append("3") | |
array.append([4, 5, 6]) | |
array.append([7: "7", 8: "8"]) | |
// prints "true" |
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 BaseRequirements { | |
// List common requirements here. | |
} | |
protocol AdditionalRequirements { | |
// Any additional reqs here. | |
} | |
struct BasicType: BaseRequirements { | |
// I will only do the basics. |
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
public static IEnumerable<T> FindVisualChildren<T>(this DependencyObject e) where T : DependencyObject | |
{ | |
if (e == null) yield break; | |
VisualTreeHelper.GetChildren(e).Filter(child is T).Map(child => () | |
{ | |
if (children != null) | |
{ | |
yield return children; | |
} |
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
// | |
// TableViewController.swift | |
// TableViewExpansions | |
// | |
// Created by Vesza Jozsef on 05/05/15. | |
// Copyright (c) 2015 Vesza Jozsef. All rights reserved. | |
// | |
import UIKit |
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
public class Box<T> { | |
let unbox: T | |
init(_ value: T) { self.unbox = value } | |
} | |
public enum ResultType<T> { | |
case Success(Box<T>) | |
case Error(String) | |
} |
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
public class BinaryNode<T: Comparable>: Comparable { | |
var value: T | |
var left: BinaryNode<T>? | |
var right: BinaryNode<T>? | |
init(value: T) { | |
self.value = value | |
} | |
NewerOlder