@interface Person : NSObject{ NSString *name; int age;}- (NSString *)name; //get method- (void)setName:(NSString *)value;- (int) age; //get method;- (void)setAge:(int)age;- (BOOL)canLegallyVote;//another way to creat property//property declarations@property int age;@property (copy) NSString *name;@property (readonly) BOOL canLegallyVote; - (void)castBallot;@end // implementation file@implementation Person;- (int) age {return age;}- (void)setAge:(int) value{ age=value; } - (NSString *) name {return name;}- (void)setName:(NSString *) value{ name=value;} //calling method- (BOOL)canLegallyVote { return (self age>=18);}//antoher way to write it@synthesize age;@synthesize name;- (BOOL)canLegallyVote{ return(age >18);} - (void)castBallot { if([self canLegallyVote]){ //do voting stuff}else { NSLog(@"I'm not allowed to vote yet!");}}} @end // Autoreleasing example- (NSString *)fullName{ NSString *result; result=[[NSString alloc] initWithFormat:"%@ %@" , firstName, lastName]; [result autorelease]; return result;}
ihpone SDKMAC OS 10.5http://tinyurl.com/cs193p-2010注册证书http://cs193p.stanford.eduhttp://developer.apple.comhttp://devforums.apple.comhttp://cs193.comcocoaSDKTOOLS:Xcode开发工具interface BuilderFramworks Foundation UIKit
Class is a blueprint for instances.Instance: a specific allocation of a classMethod: a function that an object knows how to performInstance Variable(or ''ivar"): a specific piece of data belonging to an object.Encapsulation: keep implementation private and separate from interfacePolymorphism: different objects, same interfaceInheritance: hierarchical organization, share code, customize or extend behaviors.Objective-CStrict superset of CMix C with ObjCOr even C++ with ObjC (usually referrend to as ObjC++)A very simple language, but some new syntaxSingle inheritance, classes inherit from one and only one superclassProtocols define behavior that cross classesDynamic runtimeLoosely typed, if you'd likeClasses and ObjectsClasses declare state and behaviorState (data) is maintained using instance variablesBehavior is implemented using methodsInstance variables typically hidden Accessible only using getter/setter methodsDot Syntaxconvenient shorthand for invoking accessor methodsfloat height = [person height];foat height = person.height;[person setHeight:newHeight];person.height = newHeight;[[person child] setHeight:newHeight];// exactly the same asperson.child.height = newHeight;Dynamic and static typingDynamically-typed object id anObjectStatically-typed object Person *anObject Objects represented in format strings using %@
文档及作业下载:http://www.stanford.edu/class/cs193p/cgi-bin/drupal/downloads-2011-fall
UIkit 用户界面portable miciphone SDK