Declaration of the Car.h//class//Class Name: car//property: m_nspeed//behavior: Run#import <Foundation/Foundation.h>//Nsobject@interface Car:nsobje ct{//Properties: member variables (which can be the underlying type, enumeration, struct, and class object pointers) @publicint m_nspeed;//default initialized to 0}//behavior: Method (method name, return value, parameter)-(void) stop;-(void) run: (int) Speed Type requires parentheses-(bool) Turnwithspeed: (int) speed anddirection: (int) direction;//can be only colon-(BOOL) turn: (int) Speed: (int) direction;//method names include colons: Turnwithspeed:anddirection://turn: @end
Implementation of the car.m//class @implementatiom car//Car class name-(void) Stop{nslog (@ "Stop");} -(void) run: (int) speed{self.m_nspeed = speed; NSLog (@ "Run speed =%d", self.m_nspeed);} -(BOOL) Turnwithspeed: (int) speed anddirection: (int) direction//-(BOOL) Turn: (int.) Speed: (int) direction{self.m_ Nspeed = speed; NSLog (@ "Run speed =%d, direction =%d", self.m_nspeed, direction); return YES} @end
Use of the main.m//class #import "Car.h" int main () {car* car = [car new];//Create an instance of class Car->m_nspeed = 60;//Class Property access [Car Stop][car Run:6 0][car turnwithspeed:60 Anddirection:1]return 0;}
iOS Review Note 3: basic definition of class