Friday, October 22, 2010

First Thing to Learn Objective C [1]

Topic: Devevlop Language, Tools and Environment and Simple Important Things
Language: Objective-C, cames from c and smalltalk
Cocoa: Like STL in C++, Swing in Java,
XCode: Like VisualStudio or Eclipse IDE
Interface Builder: << WYDWYS

Recommand Book:Programming in Objective-C" by Stephen Kochan
Beginning iPhone 3 Development: Exploring the iPhone SDK" By Jeff LaMarche and David Mark

Target: Practise and to Earn Money with your hard work!
FreeLance http://www.ifreelance.com/Freelancers/Freelance-Apple-Programmers/

Step1: Basic Concept 1 (Must to know) Quickly go-through it, learn from everywhere, here is only list some key points
All public
-+:  function, method, start
: means passed-in parameter!

Compare with Java code: private void hello(bool ishello)
{ //OOXX }
In Objective-C:
-(void) hello:(BOOL)ishello
{ //OOXX }

In my words: +: Means statics member of class
[] means what?  For example: [self hello:YES];   --> this.hello(true);

Your will see NS in everywhere in the objects name? Why? Because NS means NextStep??? Job's previous company name...
[My Notes: What's your next step?]

Hear are examples, which you are using every minutes and every seconds.
NSLog
NSString
NSInteger
NSURL
NSImage
Statement Example:NSLog (@"%d",myInt);
@: NSString using by NSLOG

CFStringTokenizer : Core Foundation
CALayer : Core Animation
CGPoint : Core Graphics
UIImage : iPhone picture
Here interface is Class(in Java/C++),
@interface:
In kids.h
@interface Kids: NSObject {
NSString *kidName;
NSString *kidAge;
}
-(BOOL) isCaughtKid:;
@end

kids.m (implementation!)
#import “kids.h”
@implementation Kids
-(void) init {
  kidName=@”mykid”; 
  kidAge=@”15”;
}
-(BOOL) isCaughtKid:{
   return YES;
}
@end

Case in Pass-in Many Parameters-(void) setKids: (NSString *)myOldestKidName secondKid: (NSString *) mySecondOldestKidName thirdKid: (NSString *) myThirdOldestKidName;
-(void) setKids:
(NSString *)myOldestKidName secondKid:
(NSString *) mySecondOldestKidName thirdKid:
(NSString *) myThirdOldestKidName{
son1 = myOldestKidName;
Son2 = mySecondOldestKidName;
Son3 = myThirdOldestKidName;
}
When you call:
Kids *myKids = [[Kids alloc] init];
[myKids setKids: @”SonName1” secondKid: @”SonName2” thirdKid: @”SonName3”];
testing:[[[MyClass alloc] init:[foo bar]] autorelease];
--> MyClass.alloc().init(foo.bar()).autorelease();

Others Powerful Points:id: data type as ANY, everything save as point, id give the address of WHATEVER...
NSArray: can save anything type of data
myArray <—-|
0: (float) 234.33f
1: @”I'm good.”
2: (NSImage *) (MyPic.jpg)
3: @”My adress is”
BOOL(YES,NO), (1, 0)
IBOutlet, IBAction
IB: Interface Builder, outlet: add it at front when you want see from outlet
Action:
nil: null pointer
@: convert to NSString, NSLog need,

Real Example of Helloworld:
import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    NSLog(@"Hello, World!");
    [pool drain];
    return 0;
}
My Note: Can you understand it now?...Congradulation!!

No comments:

Post a Comment