O'Reilly logo

Cocoa Programming for OS X: The Big Nerd Ranch Guide by Aaron Hillegass, Adam Preble, Nate Chandler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Add Cut, Copy, and Paste to Dice

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:

 ​ ​ ​ ​/​/​ ​M​A​R​K​:​ ​-​ ​P​a​s​t​e​b​o​a​r​d​

 ​ ​ ​ ​f​u​n​c​ ​w​r​i​t​e​T​o​P​a​s​t​e​b​o​a​r​d​(​p​a​s​t​e​b​o​a​r​d​:​ ​N​S​P​a​s​t​e​b​o​a​r​d​)​ ​{​
 ​ ​ ​ ​ ​ ​ ​ ​i​f​ ​l​e​t​ ​i​n​t​V​a​l​u​e​ ​=​ ​i​n​t​V​a​l​u​e​ ​{​
 ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​p​a​s​t​e​b​o​a​r​d​.​c​l​e​a​r​C​o​n​t​e​n​t​s​(​)​
 ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​p​a​s​t​e​b​o​a​r​d​.​w​r​i​t​e​O​b​j​e​c​t​s​(​[​"​\​(​i​n​t​V​a​l​u​e​)​"​]​) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required