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

Mac Programming Lesson 1 part 1


3m read
·Nov 3, 2024

Processing might take a few minutes. Refresh later.

Hey guys, this is Mack, and one in this complex, maybe two or three parter Objective C lesson one, I'm going to be teaching you how to use the Coco Library, how to declare variables, how to initialize NS strings, and much more.

In this first Mac programming lesson, we're going to make a simple application that has one window. In the window, there's a label and a button. When you click the button, the label's text changes. The label's text is also the amount of seconds since 1990 or since 1970 when you first open the application, and it'll continue being the amount of seconds since 1970 whenever you click the button.

So open up Xcode, and I'll make a new application, a Coco application, and I will call it "Time Since Then." The time we're actually getting is called the Epoch time. There's a C function that will get the Epoch time, which is the time since 1970, but it's cool to be able to incorporate this in your Objective C code.

First of all, we're going to add a new class that Interface Builder is going to be interacting with. Since I showed you how to use classes in Java, hopefully, you're following that and you will be more familiar. So I'm going to create a new Coco Objective C class. I'm going to call it "AppControl." This is a class that I will soon include in my Interface Builder project.

Variables are very much the same in Objective C as they are in Java. So it's the class name or variable name, and then the name of the variable. Normally, you'd put a star before the name of the variable to make it called a pointer, and I'll explain that more to you later.

So right here, I'm going to make a variable that is an NS text field class, and that's what a label is. So I'll make you have to type IB Outlet before it. I'll explain that to you in a second. Then I'll declare it as NS text field star and then I'll call it "label1."

So IB Outlet is something that gets removed when you actually build and go your app, but it tells Interface Builder that you want—it's possible to link up an NS text field in the actual interface to this variable. So when the NS text field in the interface, which will be our label, will be able to be linked up to this variable, that means when this program actually gets run, this variable will be that text field.

Now here's where it says "add interface." Add interface is where all the variables and stuff will be. Before this add end is where all the methods and functions will be. By the way, we are in "AppController.h." The H is where things are declared, but you don't actually write any actual code. You just tell the computer that you want to have functions and variables with these names.

The M is where you actually type your code in the actual code that happens. So the way you declare a method is you do dash before the method, then left press paren. The return type of the method with parentheses, IBAction, gets replaced with void when you actually build and go the application, but it's once again for Interface Builder to recognize that you can link this up with something.

Then after the close parentheses, you do the method name. So I'll say "buttonClicked," and then for the first parameter, you just do colon left parentheses again, the variable type. I'm going to NS button star, and then the variable name I'm going to call it "sender."

So the way this will work is, in Interface Builder in a moment, we're going to make it so when they click this button, it calls this method on this class AppController, and this way it'll pass as the first parameter the NS button that triggered the event. So when you click an NS button, that calls "buttonClicked," and sender will be the NS button.

So I'm going to copy this and implement it in the M. It's exactly the same here except you use curly braces to do this. So right here, it's just saying, “Okay, I'm going to have something that's like this in here.” It's saying, “Okay, I want to have an IB Outlet variable.”

So this is the code inside of these two curly braces that will happen when they click the button. So, I'm going to say label one, which…

More Articles

View All
Relative clauses | Syntax | Khan Academy
Hello grammarians! Hello Rosie! Hi David! So today we’re going to talk about a special kind of dependent clause, which again is a kind of clause that can’t be a sentence on its own, called a relative clause. A relative clause is a dependent clause that s…
3-D Technology Offers Clues to How Egypt’s Pyramids Were Built | Nat Geo Live
My archaeological team actually is very unique because I’m the only ecologist, and the other members are computer scientists, software engineers, and applied mathematicians. We are like a crime scene investigation, patiently documenting with the latest te…
Compound interest: How to turn $1 into $10
What’s up you guys? It’s Graham here. Since today, I’m going to be telling you guys how to trim $1 into $10. And it’s not some stupid [ __ ] sales pitch. I’m not trying to get you to invest in some [ __ ] mother; I hate those people. So I’m not trying to …
The First Meeting of EDUtubers! ft. CGPGrey, Vsauce, Smarter Every Day, Numberphile +more
Hey, Veritasium! Michael [Stevens] from Vsauce here, and we’re gonna ask some important questions. Let’s find some random bystanders…how about you? Yes? Michael: I don’t believe you’re scientifically literate. Okay. Michael: If a tomato is a fruit, do…
Catch of the Week - Hundred-Incher | Wicked Tuna
[Music] Oh nice, Mark. [Music] Dude, we’re on! It’s a big one! Go to work! Yes, sir! Thank God that Drake freed us from the anchor line earlier, or we wouldn’t be able to chase this fish down. Get him, get him, get him! Get some, baby! Get some! Nice wor…
Enthalpy of formation | Thermodynamics | AP Chemistry | Khan Academy
Enthalpy of formation refers to the change in enthalpy for the formation of one mole of a substance from the most stable form of its constituent elements. Change in enthalpy is symbolized by delta H, and the F stands for formation. The superscript naught …