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

xCode Lesson 2 (Write The Code)


3m read
·Nov 3, 2024

Matt: "Kids 101 here! Today this is an X good lesson too. So right here I have my Xcode project we started in Xcode lesson one called Hello Taco. Right now we've just designed the interface, and it looks like this.

So first of all, to start putting in code, we go to Action, add new file, then under Cocoa, Objective-C class. Then we click Next, and then we take the file name. I'm going to call it code, and we have to leave the damn there. And then, yeah, so it'll come out somewhere in some folder. So you just want to click it and drag it into, say, Classes.

You want to click and drag it into Classes, and then you want to click Code.h and just start editing it. I'll just double click it to bring this up. Then, in Code.h, you want to type the following code:

@ib outlet

I'll make this get bigger and I'll put this code in the description. So I'm right here. I'll just, um, @ib outlet space NS text field. And don't even try to guess the capitalization on this space star. And then I'll type, um, let's just call it mainTextField. Then have a semicolon. And then, so that's then we hit under another @ib outlet space NS text field space star. And then we're going to call this nameLabel and then have a semicolon.

Ok, and now under the curly brace on the line before the @end, we type - (IBAction). I’m taking that will point out that all this code is in the description. Then close parentheses, and then I'm going to say, um, buttonClick: and then another open parenthesis, ID, close parentheses, and then I'm going to type sender. Then we put a semi colon and we press Apple has to save. Ok, and I'll close that.

So now I've typed that code in Code.h. Let's just build and go. So still the same. So now we want to go up to Hello Taco, open the MainMenu.xib again, and then on our window, first of all, we want to go back into Library, find the thing that looks like a little blue box called NSObject, drag that into the window with all the files in it.

And then in the Attributes Inspector, we click the little I information thing, and then we set the class to be the name of the class we made. I called it code. Now we save that, hit enter.

Now first of all, we click Control and keep on holding Ctrl and drag it up to here. I don't even click mainTextField and I can click hold Ctrl and drag it over this label that says name in it. Let go, and we're going to call it nameLabel. So we click nameLabel and then we click the Go button, hold Control, drag it down to Code. Let go, then click buttonClick. Ok, so now we've tied in all the codes, and we are officially done with Interface Builder.

Now let's edit Code.m. And then here we want to type - (IBAction) buttonClick: just the same name as the other one, colon, (id)sender;

Or no semicolon. Finally, hit enter. We do an open curly brace, then we hit enter. I'm gonna do a close curly brace. In between those curly braces, I made another line.

So what we're going to do in here is we're going to type [nameLabel setStringValue:[mainTextField stringValue]]; semi colon. And then, yeah, so now we can save our clock to File, save. Now let's build and go. Right here, I'll type, my name is Dave.

It goes, and it says, 'my name is Dave.' I tagged Alex in the color, and it says, 'Hello Alex Nickel.' So this is effectively useless, but it's cool.

We could also go into Product folder, grab HelloWorldApp, copy that by pressing Apple or Command C, click this, then Command V to paste right here. It's on my desktop. This is the final application, so now you can send this to anyone we want.

So this is the application. So, that's how to make a simple Hello World application. Thank you for watching, Mad Heads on our one, subscribe, and goodbye!"

More Articles

View All
MARIO'S MISTAKES? -- Chat with Black Nerd Comedy --
Hey Vsauce, how are you doing? Happy Wednesday! And we have a special treat for you today because Mario turned 25 years old last week. I have a confession to make: because of my troubled childhood, I didn’t get to learn enough about Mario. But I’ve got a…
The 5 Biggest Mistakes People Make In Their 20’s (And How To Avoid Them!)
What’s up you guys? It’s Graham here. Now, it sounds really weird to say, but I’m nearly finished up with my 20s. In two years, I’m gonna be 30 years old! That sounds really weird to say; that’s trippy. The same almost 30 sounds better than saying 28. Bu…
Resurrecting Notre-Dame de Paris | Podcast | Overheard at National Geographic
[Music] I took a taxi there, and it was still dark when I got there. It’s kind of like entering a space station or something. You show up, shed all your clothes, put it in lockers, go through this vestibule, and you come out on the other side wearing a cl…
These Huge Rats Can Sniff Out Land Mines | National Geographic
We bring the Gambian Jan rats from Africa to sniff out the landmines in Cambodia. There is a two million landmines spread out in Cambodia. Two hundred to three hundred people got injured by landmines and you SOS every year. These rats look similar to the…
Apache Youth Reclaim Their Story Through Skateboarding | Short Film Showcase
[Music] [Music] [Applause] [Music] Here in San Carlos, you can’t just jump on the train, jump on a subway, jump on a light rail, and go to the multiplex. I think sometimes Native adults have said, “Oh, Native kids, they’re losing their culture.” They have…
How our actions are making raccoons smarter | Webby Award Winner | Nat Geo Explores
[Narrator] These little creatures can be complicated. They’re cute, but mischievous. It’s my pizza. They may have earned a bad rap from their antics, but their problem-solving skills inspire scientific studies. Interactions with them are unpredictable, an…