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

Mac Programming Lesson 2 part 1


3m read
·Nov 3, 2024

Processing might take a few minutes. Refresh later.

Hey guys, this is Mac Kids, and on with Mac programming lesson two. So, this programming lesson isn't going to be about polishing your application or gooey stuff; it's going to be about understanding. Because basically, I watched a bunch of Partners videos and professional YouTube videos on how to program, and it seemed like after watching their videos, you might actually be able to make a good application all by yourself. But you may not necessarily truly understand what's going on.

Understanding what's going on in things like C and Objective-C is something that takes a long time. I've been doing C for almost a year, and just a month ago, I actually started to understand what I'm actually doing. By now, I pretty much get what's going on. And so, as I'm not the best teacher ever, I'm going to try my best to pass the information along. But you may not catch the drift, so this is hard.

I'm going to be using a terminal application to get you guys to really understand what variables are and what pointers are. Because in, say, um, Java, it's pretty easy to understand; there are no stars, there's no, like, nothing. A variable is just a variable, and you can use dots to do stuff with it. But with this, I have to teach you guys what you're actually doing because in Java there is no like, what you're actually doing, because you don't have that kind of power.

So, I'm going to make a new project, and I'm going to go under command line utility. I'm going to click Foundation tool. I'm going to call it, um, plain old learning, just to represent we're just learning stuff; there's nothing new. And so, you'll notice under Source, there's one M file, which is plain old learning.m. This is where we're going to put our stuff.

So, let's start from the ground up. Right here is a C function. This is how you normally would declare a function in C; it's variable type space, you know, thingy space, left parentheses, parameters, right parentheses, and at the top there's an import. What this import does is it uses the Foundation Library, which has things like NS3 ring in it.

So now from there, you might notice that NSLog takes something that starts with at, then two quotes, and inside of that quotes can be whatever you want. Whenever you put an at before quotes, it knows that you want to put an NSString there, and it converts what's inside of those quotes to be an NSString.

People didn't understand at is like a magic character in Objective-C, especially this version of Objective-C, that will tell everything basically that you want to make an NSString or you're going to synthesize something. It's really an important thing to notice; if you get rid of the at, then it thinks you're just giving it a character array. Because this is, of course, C, and in C, you declare a character array with quotes, so that's not exactly how this is going to roll.

I need to get rid of this NSLog; we're going to ignore that for now, and we're just going to type in between this NSAutoreleasePool and pool drain. So right here, first of all, you know when you're declaring a string in Objective-C, the class name or variable name is NSString. Then you do a space and then normally you do the variable name in Java, but you know, to do a star somewhere between the variable name and the, um, variable type.

So I'm going to make an NSString *foo, and you know we have to do that star there, but you're not exactly sure why. The star means that I'm not going to specifically own foo; all foo is going to be is a little number that represents some place in my RAM, in my memory. So foo in this case, since it's a 32-bit application, will be four bytes, and that's four characters or four numbers.

So foo is going to be four numbers, um, and that tells the computer where in memory all of the memory can be represented by four different numbers. So foo is just going to point to something else. So when we say foo =, we're just going to be changing the four numbers that it is, not what's actually in it.

So say I do NSString *foo =; then I'll do left bracket, left bracket, NSString alloc, init. Now, first of all, NSString alloc means we're going to make a new pl...

More Articles

View All
The Real-Life MacGyver in Nat Geo’s Basement | Podcast | Overheard at National Geographic
I want you to imagine a photograph. Okay, we’re way up north in the Canadian Arctic at a place called Ellsmere Island. This is a land where packs of white Arctic wolves prey on oxen. Okay, picture big shaggy buffalo with thick curling horns. All right, ou…
Adding whole numbers by their place values | Math | 4th grade | Khan Academy
What is 19,000 plus 7? To first, let’s think about what are 19,000 and what are 7. Then from there, we can add them. So, 19,000 would quite literally be if we had a thousand 19 times. So, there’s a thousand one time. If we had 1,000 two times, we would h…
A Case of Mistaken Identity | Shark vs Surfer
Marjorie was likely bitten by a tiger shark, one of the main culprits of shark attacks on surfers in Hawaii. Tiger sharks tend to be solitary hunters. They’re feeding on large prey items, and they have the jaws and the hardware that enable them to take th…
Shifting absolute value graphs | Mathematics II | High School Math | Khan Academy
This right over here is the graph of y is equal to absolute value of x, which you might be familiar with. If you take x is equal to -2, the absolute value of that is going to be two. Negative -1, absolute value is one. Zero, absolute value is zero. One, a…
One, Two, Three Bites, You’re Out | Wicked Tuna: Outer Banks
Michael: “Let that one go, all right? Got a double on, baby! What do you want me to do with this one?” TJ: “Let him go! Just cranking up. Keep it tight on them! Get tight on him!” F: “Watch out! What we’re here for, baby! Got a double on here. I think h…
Pike Surprise | Life Below Zero
This time of year, the pike are spawning in the shallows. There’s a grassy area just up around the corner where I might find some. I haven’t caught a pike yet this year, so you never know exactly what you’re going to find, but I’m hoping for some good fis…