So , I have an interview tomorrow and I am going to brush up on my Objective-C and iPhone development. *these posts are going to be really embarrassing if I don't get the job.. yikes oh well* And when I teach what I am learning it sticks better so buckle up you're about to learn some Objective-C. *confetti falls from celling*
Alright first off, what is Objective-C?
- Objective-C is most often used whenever you are programing in the iOS or the OS X operating systems.
- Objective-C also provides object-oriented capabilities and dynamic runtime
Fancy stuff. So in non technical terms , Objective-C is mostly used in Apple products , and the dynamic run time means that objective-c decides which method implementation to call right before calling it.
COOL.. movinggggg on...
Let's do some code together shall we?
To start off we will cover some basic syntax -
A Class-
*NOTE CLASS NAMES MUST BE UNIQUE.. like you ;)
So a class is simply called by typing the following :
So a class is simply called by typing the following :
--> @interface HannahClass : NSObject
--> End
--> End
Righto simple enough. Next step is we are going to document name and twitter handle. These are called properties. They're called like this.
@interface HannahClass : NSObject
@property NSString *name;
@property NSString *handle;
end
Sweet. So now our app uses the class Hannah and has two string properties within it that holds my name and my twitter handle.
- please note that we use the asterisk to indicate that they are c-pointers. So basically memory stuff.
@property NSNumber *birthDay;
@property int *birthYear;
Right. Noted that int isn't an NS because I fudged that up the first time. *thehe*
How to call a method. SIMPLE.. I got this..
--> (void)someMethod;
BOOM. That's how it's done. Yes yes I realize that if you're coding on a mac and using XCode it most likely autocompletes this for you but ya know. WHAT IF YOUR XCODE JUST DIES AND YOU SUDDENLY NEED TO CODE BUT YOU CAN'T USE XCODE. Hmmm that's what I thought.
Much like any other language methods can take parameters.
--> (void)someMethod : (someType) value;
Same thing but with more than one param -
--> (void)someMethodWithFirstValue :(SomeType)value1 secondValue:(AnotherType)value2;
Same thing but with more than one param -
--> (void)someMethodWithFirstValue :(SomeType)value1 secondValue:(AnotherType)value2;
cool beans..
I think that's enough review for the moment as I am very tired. BUT.. I wish all of you a happy day! If anyone reads this far haha.
*disclaimer : The source i used for objective-c was here
*disclaimer : The source i used for objective-c was here
No comments:
Post a Comment