Mac Programing Lesson 1 Part 2
Thank you for continuing to watch this video. If you have not seen part one of this video, it would be smart to watch that first because otherwise this part won't make any sense. Thank you, enjoy the video.
So I'm going to declare an NS string, and I'll put star here, and I'll call it, um, time string, and I'll say it equals a new string. Now, in Java, you would do new string. In Objective C, you have to allocate it and initialize it, so you do left parentheses or left bracket NS string alloc right bracket, put that in brackets, and then outside of those brackets call a nit with format.
And then here's where we put the format. So I'm just going to do percent D, and as the next parameter to a nit with format, I'm going to set it to be time, time left parentheses null. So time is an old C function, and you just pass it something that doesn't matter, so I'll just pass it null.
So now we're going to have an NS string that is not only allocated, but it has the time in it. And just for fun, I'm just going to say t equals, or no, I'll just do T colon space, and then percent D to show you that it is in fact a format.
So if you remember from C, you do percent D, and that means in the next parameter, you're going to have to pass it an integer. So time is a C function that returns an integer, so now we're going to have a string called time string that's an integer.
So now, if we set the string value to time string, it'll say T and then, you know, the time. So this is easy. We're going to also call this when it loads.
So when every application loads, um, what happens is the program looks at every single one of the objects here and looks for a method on them called awake from nib, and it calls awake from nib on them. Awake from nib is just something that gets called when everything is loaded.
So if I implement awake from nib, I don't have to add it to myh because it's built into every class. Um, so if I add it here, this code will run when the application starts up, so I'll just paste the exact same thing there.
So now, if you watch, it says T and then the Epoch time, time since 1970. If I click it again, it'll keep on changing. Now the label's not quite wide enough to display the whole Epoch time, so I'll make this window a little wider.
So it is changing there, so this is how to make our application. I was rushing through this because I wanted to be very, um, very fast, maybe make it just a two-parter, not a three-parter.
And I'm sure you'll all have very many questions for me, and I'm fine with that, so please ask away. Anyway, thanks for watching. My kids in the one, look forward to Objective C lesson two for the Mac with Coco. Um, anyway, subscribe and goodbye.