1

I'm trying to learn how to capture screenshot with Mac OS X'a Cocoa. I found online a very nice example called Son of Grab:

https://developer.apple.com/library/mac/samplecode/SonOfGrab/Introduction/Intro.html#//apple_ref/doc/uid/DTS10004490-Intro-DontLinkElementID_2

However, I can't figure out how to build it as an app in XCode. When I create a simple command line project it just complains that info.plist is not available. If I create a Cocoa application and just put the 3 files (main.m, Controller.h, Controller.m) into the project, nothing happens.

I did more research and tried to use Controller in my AppDelegate. here's my AppDelegate class

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    self.controller = [[Controller alloc] initWithWindowNibName:@"Controller"];
    [self.controller showWindow:self];
}

I created a simple Controller.xib which is just a window. This, however, causes an infinite loop in the awakeFromNib method inside of Controller.m.

I'm quite confused now, and I'm quite new to Cocoa and Objective-C. Any pointers will be greatly appreciated.

1 Answers1

0

I'm guessing that you are using the links in the sidebar of the sample project page you linked to and you're downloading just those few files (main.m, Controller.h, and Controller.m). That's not the right approach. You should click the Download Sample Code button in the bar at the top of each page. That will give you a complete Xcode project that you can open in Xcode and just build and run.

If you're not seeing the button for some reason, it just links to https://developer.apple.com/library/mac/samplecode/SonOfGrab/SonOfGrab.zip.

The web site is showing just those files which make sense for a human to read. It omits the Xcode project, Info.plist, main menu NIB, etc. But the downloadable zip archive includes all of that.

Ken Thomases
  • 88,520
  • 7
  • 116
  • 154