 		UIButton.appearance().tintColor = KeyboardAppearance.secondaryButtonColorForApperance(appearance)
     }
 	
+	func casedLetterForLetter(letter: String) -> String {
+		switch self.shiftState {
+			case .Locked, .Enabled:
+				return letter.uppercaseString
+			case .Disabled:
+				return letter.lowercaseString
+		}
+	}
+	
+	func typeLetter(letter: String) {
+		let proxy = self.textDocumentProxy as UITextDocumentProxy
+		let casedLetter = casedLetterForLetter(letter)
+		proxy.insertText(casedLetter)
+		
+		switch self.shiftState {
+			case .Locked:
+				break
+			case .Enabled:
+				self.shiftState = .Disabled
+			case .Disabled:
+				break
+		}
+	}
+	
+	func deleteCharacter() {
+		let proxy = self.textDocumentProxy as UITextDocumentProxy
+		proxy.deleteBackward()
+	}
+	
+	func deleteWord() {
+		let proxy = self.textDocumentProxy as UITextDocumentProxy
+		if let precedingContext = proxy.documentContextBeforeInput {
+			let numTimesToDelete = precedingContext.numberOfElementsToDeleteToDeleteLastWord()
+			for i in 0...numTimesToDelete {
+				proxy.deleteBackward()
+			}
+		}
+	}
+	
 	// MARK: Gestures
 	
 	func didTap(sender: UIGestureRecognizer) {

	/// TODO: Fix this once `documentContextBeforeInput` stops always returning nil.
	/// Did a left swipe gesture. Delete until previous chunk of whitespace.
	func didSwipeLeft(sender: UIGestureRecognizer) {
		let proxy = self.textDocumentProxy as UITextDocumentProxy
		if let precedingContext = proxy.documentContextBeforeInput {
			let numTimesToDelete = precedingContext.numberOfElementsToDeleteToDeleteLastWord()
			for i in 0...numTimesToDelete {
				proxy.deleteBackward()
			}
		}
	}
	
	func shiftKeyPressed(sender: UIButton) {
		
	}
	
	func deleteKeyPressed(sender: UIButton) {
		let proxy = self.textDocumentProxy as UITextDocumentProxy
		proxy.deleteBackward()
	}
}

// Some constants to use.
let APPEAR_ANIMATION_DURATION = 0.3

/// Represents the state of shift
enum KeyboardShiftState {
	/// Shift is disabled—- types lowercase.
	case Disabled
	/// Shift is enabled-- types capitals.
	case Enabled
	/// Shift is locked-- continue to type capitals.
	case Locked
}

class KeyboardViewController: UIInputViewController {
	
	let row1 = KeyboardViewController.createRow()
