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
// Light-weight Swift smart quote implementation | |
// By Rob Hudson | |
// 5/11/2015 | |
import UIKit | |
let text = "\"Would you tell me, please, which way I ought to go from here?\" " + | |
"That depends a good deal on where you want to get to,\" said the Cat. " + | |
"\"I don’t much care where-\" said Alice. " + | |
"Then it doesn’t matter which way you go,\" said the Cat. " + |
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
// objc.io Issue #9 | |
// February, 2014 | |
// String Parsing by Chris Eidhof | |
// | |
// Swift version by Rob Hudson | |
import UIKit | |
// NSTextCheckingResult using NSRange, rather than Range<String.Index>, so we need an NSString, rather than a String | |
let string: NSString = "backgroundColor = #ff0000" |
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
// objc.io Issue #9 | |
// February, 2014 | |
// String Parsing by Chris Eidhof | |
// | |
// Example 2 | |
// Swift version by Rob Hudson | |
import UIKit | |
let FormatError = 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
// objc.io Issue #9 | |
// February, 2014 | |
// String Parsing by Chris Eidhof | |
// | |
// Example 3 | |
// Swift version by Rob Hudson | |
import UIKit | |
let FormatError = 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
func sendEmail(email: Email, completion: SendEmailCompletionBlock) -> Request { | |
let fields: JSONDict = [ | |
"first_name" : email.firstName, | |
"last_name" : email.lastName, | |
"email_address" : email.emailAddress, | |
"ip_address" : email.ipAddress, | |
"vendor_id" : email.vendorID, | |
"event_date_epoch" : email.eventDateEpoch, | |
"message" : email.message, | |
"phone" : email.phoneNumber |
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
struct NoteSpeller { | |
static let wordURL = "https://raw.githubusercontent.com/dwyl/english-words/master/words.txt" | |
static let delimiter: Character = "\n" | |
static let notesNames: [Character] = ["a", "b", "c", "d", "e", "f", "g"] | |
static func getWords(includeH: Bool = false) -> [String] { | |
var notes = notesNames | |
if includeH { | |
notes.append("h") |
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 | |
struct Random { | |
static func randomNumberUpTo(upTo: Int) -> Int { | |
return Int(arc4random_uniform(UInt32(upTo))) | |
} | |
static func randomNumberInRange(range: Range<Int>) -> Int { | |
let distance = range.endIndex - range.startIndex | |
let random = randomNumberUpTo(distance) |
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 ordinal(forNumber: Int) -> String { | |
let tens = (number / 10) % 10 | |
let ones = number % 10 | |
let suffix: String | |
switch (tens, ones) { | |
case (1, _): | |
suffix = "th" | |
case (_, 1): |
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
// Returns 30 or 31 (except for February) | |
NSCalendar.currentCalendar().rangeOfUnit(.Day, inUnit: .Month, forDate: NSDate()).length |
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 ListNode: ExpressibleByArrayLiteral { | |
public var value: Int | |
public var next: ListNode? | |
public init(_ value: Int, next: ListNode? = nil) { | |
self.value = value | |
self.next = next | |
} | |
public required init(arrayLiteral elements: Int...) { | |
self.value = elements[0] |
OlderNewer