yego.me
💡 Stop wasting time. Read Youtube instead of watch. Download Chrome Extension

Real Cocoa Programing Lesson 1


5m read
·Nov 3, 2024

Hey guys, this is Ma Head1, and today is going to be a video on some Xcode programming to make an application I like to call EY Copy.

So first of all, you want to open up your Xcode application. You have to have Xcode installed, and it should be the latest version. Then you want to go up to File, New Project, and click under Mac OSX Applications, Cocoa Application. Now I'm going to save it to I Copy.

Okay, so now I can just, um, under EY Copy, I can just open Main Menu.xib to edit the interface. So here's my Interface Builder, and Interface Builder has a library window on the left, an attributes window on the right, a dock window, and a, um, a Main Menu. Actually, these might be reversed and they might just be in any random position, but, um, please ignore that. But to get any of these windows, if they're not up, go under the Tools menu and then click Library or Inspector.

Okay, so now this dock window will go under other windows, as you can see. So you just keep track of it. So now, if you click the Window thing in the dock window, you can edit the properties for the window, and I'm just going to call it I Copy. That's the title of the window. Under Resize, I'm going to uncheck that, and I'm going to make it textured.

Okay, now I'm going to go into my library and find a text field that looks like this, and I'm going to make two copies of it. You can just drag it on twice. Now I'm going to find the, um, button, and I'm going to drag it on, put it in the middle, and I'm going to make this an "IE Clear." Now I'm going to resize the window to be perfect.

Okay, so now we have our interface. So we're going to go up to File, Save. Now we're going to go up to Interface Builder, Quit Interface Builder. So now we want to click on the Classes folder on the left, and then under Action, you say Add New File, and then under Mac OSX, we select Cocoa Objective-C class. We're going to call it AppController.m, and now hit Finish.

Now it's under Classes, and if it's not under Classes, just drag it into Classes. Now we click on AppController. Now we're going to type here inside of this thing that says @interface AppController. Right here is IBOutlet, space, NSTextField, space, star or asterisk, text1. We're just going to copy this line and paste it there again, and we're going to change text1 to text2 on that next line.

So now we have two IBOutlets. Then under this little curly brace, we're going to type - (IBAction) close. Now we're going to say text1Done:(id)sender; semicolon. Now we're going to hit enter, and we're just going to copy that line again, except we're going to change text1Done to text2Done.

Okay, so now, um, what we want to do is we're going to create another third IBAction. Instead of text1Done or text2Done, whatever you've copied, we're going to change that to say Clear. Okay, so it's going to say clearClick. Actually, we're going to do clearClick.

So now we just want to copy these two or three IB actions, and now we can save the file. Save. Now we'll click that m, we'll paste it inside of the implementation, and we're going to get rid of the semicolons and add curly braces to each one like so. I will have this whole Xcode project up for download in the description of this video.

So now in text1Done, we're going to type some code inside of here. We're going to type [text2 setStringValue: [text1 stringValue]]; and I'm sorry, I didn't mean set text, I mean setStringValue. Okay, so that's what I mean.

Okay, so now we're going to do another close bracket there. So this is our final code for this. Okay, so now we're going to go in text2Done, we're going to copy and paste this code we put in there, except we're going to replace text2 with text1 and text1 with text2 so it looks like this.

Now under clearClick, we're going to say [text1 setStringValue:@""]; and inside of the two quotes, we're going to type nothing. Then we're going to do close bracket. We're going to copy that line again and replace text1 with text2. So this way, our clear will clear both text boxes. Text2 will set text1's string value to text2's string value, etc.

So now we want to go back into the main project right here. Now we select Main Menu.xib one more time to launch Interface Builder. So now we want to, in the library, find this blue box called NSObject and we drag this into our dock window. Now we click the object, we go under this little I thing, and under class, we're going to set that class to AppController, which you made earlier.

So now here we have AppController. So now the "IE Clear" button, we're going to click it, hold Control, and down drag it down to AppController. Now we're going to say clearClick. We're going to take AppController, drag it up to the first text box, and we're going to say text1Click. Control second text box, text2. Now, um, now we say click Control from the first text box down to AppController. We say text1Done, and then the same thing with the second text box, except we're going to click text2Done.

Okay, so now we've done all our little linkups. So now I can save this one more time. Save. And now I can quit Interface Builder. So now, if I click Build and Go, hopefully it'll work properly. Let's just wait.

So now, if I type something in here like Alex, and I hit Enter, the other box says Alex. If I type something in here like MacHeads 101, and I hit Enter, this box says MacHeads 101. Now I can also type something in here like hello, and then click this box, and this box will also say hello.

I can click "EY Clear" to clear. Now say I don't want this effect where if you just click somewhere else, it immediately changes the text. All I have to do is go back into my Main Menu.xib files and then select each. First, I'm going to select the first text box, the text field, sorry. Under the um first tab, we're going to go under Action, we're going to say Send on Enter Only.

We're going to do that with the second text field too, and this will have the effect that, um, let me just demonstrate it to you. If you do this and then you click this, it won't change the text of this. Only if you hit Enter on this will it change the text if I say hello.

Okay, but it doesn't matter if you click somewhere else. I personally like the first one more. Maybe in more advanced programming, I'll show you guys a delegate that lets you do it so whenever you press a key in one, it changes the text in the other, but now "I Clear" will still work and stuff like that.

So that's how to make EY Copy in Xcode. Right now, just to prove to you guys that I will put this functional Xcode project online, here's the folder. I'm just going to right-click it and take and press, and I'm going to upload this to our website and have a link to download it in the description of this video.

So, thanks for watching MacInOn. Please subscribe to our videos, it supports us completely, and goodbye.

More Articles

View All
Defund the NEA and PBS? That's Criminal. |Tribeca Film Festival Co-founder Jane Rosenthal |Big Think
When we started the Tribeca Film Festival, which we announced in 2001 right after 9⁄11 to really bring people back to our neighborhood, our goal was to just bring as many people back downtown as possible. When we announced the first film festival, we ask…
Why AI Hasn’t Blown Our Minds…Yet
Hypothetically, if AI is a bust in a bunch of different ways but it works extremely well fixing customer service, that’s still massive. It’s going to change our world; massive impact. Hello, this is Dalton plus Michael and today we’re going to talk about…
A Submarine Assault | WW2 Hell Under the Sea
July 31st, 1944. With Commander Lawson Ramage fixated on another target in Japanese convoy MI-11, below deck, battle helmsman Chet Stanton has made the decision to evade an escort that threatens to ram the American submarine. The crew of USS Parche wait t…
Why Empathy Is Not the Best Way to Care | Paul Bloom | Big Think
I argued empathy is a poor moral guide. It’s biased. It’s enumerate. It zaps the spirit. It can be weaponized to make us worse people. But one question I often get is what replaces it? And in my book I make a distinction between empathy and compassion. N…
My Investing Plan For 2023 (How To Prepare)
What’s up, Graham? It’s guys here. So 2023 is probably going to be one of the most confusing years for investing. After all, stocks are the cheapest they’ve been in two years, but there’s a chance they could drop even further. Real estate has only starte…
Meet Julia Delmedico
I’m Julia, and I’m 17. My parents are from Argentina, and I’ve grown up in Manhattan my whole life and go to school in the Bronx. I think a lot of high schools are trying to get their students into the best colleges. And because the way students are bein…