-1

I am learning Objective-C + Cocoa. According to a very outdated book (there are no newer ones like this one), I need to do the following:

Create the application.
Create a new Cocoa application named VideoPlayer.
Once the project has been created, you need to add the required frameworks. Select the VideoPlayer project at the top of the project navigator; the project information will open in the main editor.
Click the + button under the list of frameworks in the Linked Frameworks and Libraries section. Add the AVFoundation, CoreMedia, and QuartzCore frameworks to the projects.
Drag the sample video into the project navigator.
The interface for this project will consist of an NSView, which will host the AVPlayerLayer, as well as buttons that make the video play back at normal speed, play back at one-quarter speed, and rewind. In order to add the AVPlayerLayer into the view, that view must be backed by a CALayer. This requires checking a checkbox in the Interface Builder — once that’s done, the view will have a layer to which we can add the AVPlayerLayer as a sublayer. Create the interface.
Open MainMenu.xib.
Drag a custom view into the main window. Make it fill the window, but leave some space at the bottom. This view will contain the video playback layer.
Drag in three NSButtons and place them underneath the video playback view. Label them Play, Play Slow Motion, and Rewind. To add an AVPlayerLayer to the window, the view that it’s being inserted into must have its own CALayer. To make this happen, you tell either the video playback view or any of its superviews that it should use a CALayer. Once a view has a CALayer, it and all of its subviews use CALayers to display their content. Make the window use a CALayer.
Click inside the window and open the View Effects inspector, which is the last button at the top of the inspector.
The Core Animation Layer section of the inspector will list the selected view. Check the checkbox to give it a layer (Figure 8-1).
Connect the code to the interface.
Now that the interface is laid out correctly, we’ll make the code aware of the view that the video should be displayed in and create the actions that control playback.
Open AppDelegate.h in the Assistant. Control-drag from the video container view into the AppDelegate’s interface. Create an outlet called playerView. Control-drag from each of the buttons under the video container view into the AppDelegate’s interface, and create actions for each of them. Name these actions: play, playSlowMotion, and rewind. Now we’ll write the code that loads and prepares the AVPlayer and AVPlayerLayer. Because we want to control the player, we’ll keep a reference to it around by adding a class extension that contains an instance variable to store the AVPlayer. We don’t need to keep the AVPlayerLayer around in the same way, because once we add it to the layer tree, we can forget about it — it will just display whatever the AVPlayer needs to show. ...

Buttfield-Addison, Paris; Manning, Jonathon; Nugent, Tim. Learning Cocoa with Objective-C: Developing for the Mac and iOS App Stores (pp. 190-191). (Function). Kindle Edition.

So this item is about Control-Drag into AppDelegate.h - simply doesn't work. I've got a recent Xcode - 26 and a target OS is - macOS 15.7. I have no idea. Maybe something has changed in how this is being done?

4
  • Why do you want to learn Objective-C instead of Swift? Commented Sep 20 at 14:23
  • I want to learn Objective-C because I believe there is a huge legacy codebase written in it. I plan to learn Swift in future. Commented Sep 20 at 14:42
  • 1
    But what you are asking about here does not seem to be Objective-C at all. It appears that you are asking something about how to create outlets and actions in Xcode. Commented Sep 20 at 14:50
  • The book is about the Objective-C and the example is definitely in it. Commented Sep 20 at 15:05

1 Answer 1

2

This feature still works fine in Xcode 26. It's easier to show a picture than to explain in words. Here is a picture of me control-dragging from a button in the storyboard (left side) to the corresponding .h in the Assistant editor pane (right side). Xcode understands this and proposes to make an Outlet or an Action, just as your tutorial describes.

enter image description here

The above screenshot was taken using a storyboard-based template for the project. In this next screenshot, I've started with a xib-based template, and I'm dragging from a MainMenu.xib button directly into AppDelegate.h in the Assistant pane, exactly as described in the tutorial:

enter image description here

Sign up to request clarification or add additional context in comments.

6 Comments

I think that control-drag into the ViewController is supposed to work. But in this example they propose to control-drag into the AppDelegate.h
I don't know why they would want to do that. It may be that the tutorial is so old that view controllers didn't exist. (Indeed, it looks like it is so old that storyboards did not exist, which amounts to the same thing.) If you are not willing to adapt, you won't be able to use this tutorial (in fact, it sounds to me like you are already unable to use it).
I just want to understand why it worked before and why it doesn't work anymore and what is the proper way of doing this.
OK, I was able to do it. Hang on a moment.
There you go. You need to start the project with a XIB Objective-C template in order to get the MainMenu.xib and have it be paired by the assistant with AppDelegate. That is a very outmoded way of starting a project, to be sure, but Xcode does still support it.
Ah, I see. Thank you. Indeed I have chosen the storyboard one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.