Error adding cut and paste

I am using Xcode 14 on macOS Monterey. When I try to add the below for adding cut and paste I get an error from Xcode which says it can not find intValue in scope. What am I missing with the code below:

 func writeToPasteboard(pasteborad: NSPasteboard) {
        if case intValue = intValue {
    func readFromPasteboard(pasteboard: NSPasteboard) -> Bool {
        let objects = pasteboard.readObjects(forClasses: [NSString.self],
                                             options: [:]) as! [String]
        if let str = objects.first {
            intValue = str.toInt()
            return true
        return false

Neither of the functions declares intValue as a variable, so as far as they are concerned no such variable exists. The first function should pass it in as an argument, the second one should be declaring it as an internal optional variable & then returning that instead of a bool.

Thanks for the reply. I see what you are saying. I thought the same thing when I first saw the intValue variable, … where is this variable defined and what type would I use if I defined my own?. The thing which had me puzzled is this code is taken directly from the Cocoa Programming for OS X Chapter 21, page 325-326. So, I thought I was missing something from the book to make this code error free.

The original code works because those two functions are part of the DieView class and intView is a class attribute which can be accessed directly from the class functions.

Thanks again for the answer and your patience. As you can tell, I was looking at the code with a narrow view, I probably need to bite the bullet and go thought the whole book, but I learn best by looking at code and examining how it works.

With this in mind I was never able to download the errata or any code. Do you have a link to be able to download code or how this is done?

The book says:
“You can get help with this book at Books - Big Nerd Ranch, where you will find errata and downloadable solutions for the exercises.”

There are posts linking to both in the General Discussion section for the book