Skip to content

Instantly share code, notes, and snippets.

<!doctype html>
<head>
<style>
#test {
width: 200px;
height: 50px;
background-color: #ccc;
display: table-cell;
vertical-align:middle;
class CostlyAllocatedObject {
var description : String
init(_ isPrivate: Bool, _ isStarred: Bool, _ isUnread: Bool) {
self.description = "<Costly: Private: \(isPrivate), Starred \(isStarred), Unread: \(isUnread)>"
}
}
class ReallocateIfNeeded<T> {
enum YesNo {
case Yes, No
}
class Foo {
var bar: YesNo? = .None {
didSet {
self.baz = calculateValueForBaz()
import UIKit
let cal = NSCalendar(calendarIdentifier: NSGregorianCalendar)!
let now = NSDate()
var firstDay = NSDateComponents()
firstDay.day = 1
cal.nextDateAfterDate(now, matchingComponents: firstDay, options: NSCalendarOptions.SearchBackwards)

Der Tabulator auf Schreibmaschinen springt von Spalte zu Spalte auf dem Papier. Das ist praktisch der „nächste Ort der Texteingabe“. Insofern finde ich das vergleichbare Verhalten von Formularfeldern in GUIs (und dadurch auch die Formulare im Browser) eigentlich in sich sinnig.

Aber wer hat's erfunden? In Wikipedia steht:

In many graphical applications, especially on Windows, the Tab key will move the focus to every control or widget such as buttons so that the user interface can be used without a mouse at all (this was part of the IBM Common User Access design).

IBMs Common User Access ist scheiße zu googeln und vermutlich auch zu alt fürs Web. Schließlich war's für GUIs von Wordperfect auf alten DOS oder so gedacht. Aber in manchen Dokumenten wie diesem hier (PDF) findet man es noch. (Cmd+F nach „Tab Key“).

CUA soll von App

import UIKit
class FormattableAttributedString {
/* class */ let formatPattern = NSRegularExpression(pattern: "\\{(\\w+)\\}", options: nil, error: nil)!
var formatString : NSMutableAttributedString
var formatSpecifiers : [String: NSRange] = [:]
func uglyFirstLetterTransformation(str: String) -> String? {
if str.isEmpty {
return .None
}
let Letters = NSCharacterSet.letterCharacterSet()
let Numbers = NSCharacterSet.decimalDigitCharacterSet()
let firstLetter : NSString = str.substringToIndex( advance(str.startIndex, 1) )
// I find no better version than manually writing unwrap 1...n
func unwrap <T> (first: T?, closure: (T)->()) -> () {
if let p1 = first {
closure(p1)
}
}
func unwrap <T1, T2> (first: T1?, second: T2?, closure: (T1, T2)->()) -> () {
@ttepasse
ttepasse / gist:1c6dbc225aed56eec744
Last active August 29, 2015 14:11
Optionals with boolean values
// The following would be great, if not for this error message
// “Extension of generic type Optional<T> from a different module cannot provide public declarations”
//
// ... which seems to be a bug in Swift:
// https://twitter.com/jckarter/status/513429427179356161
extension Optional : BooleanType {
public var boolValue : Bool {
get {
class Bookmark {}
class WebView {}
class Something {}
var bookmark : Bookmark? = Bookmark()
var webview : WebView? = WebView()
var something : Something? = nil
infix operator &&! {}