April 2015
Intermediate to advanced
556 pages
17h 47m
English
Let’s add cut, copy, and paste capability to Dice. You will create methods named cut:, copy:, and paste: in the DieView class. To make these methods easier to write, you will first create methods for putting data onto and reading data off of a pasteboard. Reopen your Dice project and in DieView.swift, add these methods to DieView:
// MARK: - Pasteboard
func writeToPasteboard(pasteboard: NSPasteboard) {
if let intValue = intValue {
pasteboard.clearContents()
pasteboard.writeObjects(["\(intValue)"])
}
}
func readFromPasteboard(pasteboard: NSPasteboard) -> Bool {
let objects = pasteboard.readObjectsForClasses([NSString.self],
options: [:]) as! [String]
if let str = objects.first {
intValue = str.toInt() ...Read now
Unlock full access