Defining classes in OC
1 //Design a car class2 @implementationCar:nsobject3 //This curly brace writes all the attributes4 {5 @public6 intWheels;//Number of wheels7 DoubleSpeed//Speed8 9 }Ten One-(void) run{ ANSLog (@"the car ran."); - } - @end
Must start with @implementation and end with @end
@public The following variables are public
The method must be defined with a-start, and the return value needs to be enclosed in ().
Class needs to inherit from NSObject
Classes created by using OC
1 intMain () {2 3 4Car *car = [carNew];5Car->wheels =1;6 7NSLog (@"The car has%i .",car->wheels);8 9 [car Run];Ten One return 0; A}
1.Car *car = [Car new];//This is to create a car object
2.car->wheels = 1;//This is the Wheels property assignment to Car
3. When the value is taken: Car->wheels.
4. How to run the car: [Car run];
The creation and use of classes in IOS-DAY01_OC