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
// Source: https://oleb.net/blog/2016/12/optionals-string-interpolation | |
infix operator ???: NilCoalescingPrecedence | |
/// Provides a String default value for an Optional of any type. | |
/// Overcomes the problem with the `??` operator whare the default value must be | |
/// of the same type as the left hand side. | |
public func ???<T>(optional: T?, defaultValue: @autoclosure () -> String) -> String { | |
switch optional { | |
case let value?: return String(describing: value) |
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 testData = { (n: Int, max: UInt32) -> [Int] in | |
var array = [Int]() | |
for i in 0..<n { | |
array.append(Int(arc4random_uniform(max))) | |
} | |
return array | |
}(10, 100) |
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 | |
/// A template for comparing different sorting algorithms. | |
/// | |
/// To use: | |
/// - Sublass `SortTemplate`. | |
/// - Override the function `algorithm to sort the internal var `array`. | |
/// - Initialise the new class with data to be sorted. | |
/// - Call the `sort()` function. | |
class SortTemplate<C: Comparable> { |
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 | |
// Is the device's iOS version equal or later to the targeted version? | |
let targetOSVersion = NSOperatingSystemVersion(majorVersion:8, minorVersion:0, patchVersion:0) | |
if NSProcessInfo().isOperatingSystemAtLeastVersion(targetOSVersion) { | |
println("Running iOS version 8.0.0 or later.") | |
} else { | |
println("Running iOS version 7 or earlier.") | |
} |
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
titleLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleHeadline) | |
bodyLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleBody) | |
footnoteLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleFootnote) |
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 | |
// ColouredRose2 | |
// | |
// Created by Vincent O'Sullivan on 08/04/2015. | |
// Copyright (c) 2015 Vincent O'Sullivan. 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
func getDatedString(basicDictionary: NSMutableArray, selectedIndex: Int) -> String { | |
return basicDictionary.objectAtIndex(selectedIndex) | |
} |
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
- (NSString *) getDatedString:(NSMutableArray *)basicDictionary forindex:(int)selectedIndex { | |
return ([basicDictionary objectAtIndex:selectedIndex]); | |
} |
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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |