So far, I've learned some of the very basic statements. I can output mathematical equations and text to the console. No real program yet. I should get better progress with Objective-C than I did with Java. I didn't have too much of an interest in Java, while I'm very interested in Objective-C.
I'll be using the Mac/iPhone SDK (Xcode) for my programs. The one problem with that, it requires a mac to be able to use it, which I personally don't own. My brother and mother have one, but I can't use those. My solution? Something awesome.
You may be thinking "What am I looking at?" well, besides the Mass Effect 2 theme on my desktop, you're looking at OS X Snow Leopard running in a virtual machine in Windows 7. Basically like the Mac software Parallels, but in reverse. I won't explain how I did it since it's actually quite difficult, but I basically have a mac now. All that trouble just so that I can learn Objective-C. Worth it? Yes. Very yes.
Moving on to the actual language itself. It's not as easy as Java, but I like a good challenge. The code is a bit confusing to me since I know a bit of Java. But other than that, learning progress is slow but steady.
WARNING: The rest of this article is nerd talk.
Here's some example code that I've written.
#import <>Simple, right? Maybe to you nerds out there. All that does is output this to the console (Got rid of the timestamps):
int main (int argc, const char * argv[]){
int a;
int b;
int c;
a = 2;
b = 3;
c = a % b;
NSLog(@"a%%b=%i",c);
c = b % a;
NSLog(@"b%%a=%i",c);
c = a % a;
NSLog(@"a%%a=%i",c);
c = a + b;
NSLog(@"a+b=%i",c);
c = b + a;
NSLog(@"b+a=%i",c);
c = a - b;
NSLog(@"a-b=%i",c);
c = b - a;
NSLog(@"b-a=%i",c);
c = a * b;
NSLog(@"a*b=%i",c);
c = b * a;
NSLog(@"b*a=%i",c);
c = a * b + 5;
NSLog(@"a*b+5=%i",c);
c = a * (b + 5);
NSLog(@"a*(b+5)=%i",c);
c = (a * b) + 5;
NSLog(@"(a*b)+5=%i",c);
c = b * a;
NSLog(@"b*a=%i",c);
c = a / b;
NSLog(@"a/b=%i",c);
c = b / a;
NSLog(@"b/a=%i",c);
return 0;
}
runBesides your math homework, what does it look like to you? "Nothing" should be your answer. But to me, that's my first Objective-C program. I'll explain a few things about the code to the best of my ability.
a%b=2
b%a=1
a%a=0
a+b=5
b+a=5
a-b=-1
b-a=1
a*b=6
b*a=6
a*b+5=11
a*(b+5)=16
(a*b)+5=11
b*a=6
a/b=0
b/a=1
Debugger stopped.
Program exited with status value:0.
First off, I'll skip from the very start of the code to the NSLog deal. NSLog is basically a command to output some text (Or numbers or whatever) to the console outside of the user interface. Pretty simple.
With the int a; int b; and int c; stuff, I'm declaring the variables as integers, but they don't yet have a value. They just exist, but don't do anything. I give each variable (Symbolized by a letter after the int statement) a value by simply saying a = 2; b = 3; and c = a % b;
One thing about ints, they're whole numbers. So if you were wondering why 3 divided by 2 only equaled 1 and 2 divided by 3 equaled 0, the program rounded the numbers to whole numbers. It's easy to use decimals by just switching int with float.
To be honest, I'm kinda confused about the % deal. The books I'm reading haven't explained it in too much detail yet.
The return 0; statement makes the program end with a value of 0. As I understand it, it has to do with the computer's random access memory (More commonly known as RAM) and such. Could be wrong, though.
Even though I already knew it would be harder than Java, Objective-C is going to be a somewhat bigger challenge to learn than I originally thought. One step at a time.
Anyway, all this is a (very) simple summary of all I've learned today (And all night last night) and I have a lot of work ahead of me. I'll talk to you guys later.
Until next time, play nice. =)
Kyle
No comments:
Post a Comment
nintendude794's Youtube Channel
nintendude794's Twitter
nintendude794's DeviantArt Profile