//
Main.m
- Create an object and access the instance variable
//
Created by Vic fan on 16/7/3.
copyright©2016 year Li Hongqiang . All rights reserved.
//
//Car *car = [car new];
Class name * pointer = [ class name new];
[Car new]; have done three things :
1 requesting memory space from your computer
2 Initializing an instance variable in a class
3 Returns the memory address of the object
#import <Foundation/Foundation.h>
@interface Car: nsobject{
//@protected/// default is @protected protected , only instance variables can be accessed in the current class and subclass
@public
instance variables for the //class
int _speed; speed
nsstring *_color; // color
int _wheelcount; Wheel Count
}
declaration of a class method
@end
implementation of the class
@implementation Car
implementation of class methods
@end
int Main (int argc, const Char * argv[]) {
@autoreleasepool {
car *car = [car new];
// give the address to car
// assigning values to instance variables in a class
car->_color = @ " blue ";
car->_speed = +;
car->_wheelcount = 4;
// Accessing instance variables in a class
NSLog(@ " color :%@, speed :%d, wheel count :%d",car->_color,car->_ Speed,car->_wheelcount);
}
return 0;
}
Li Hongqiang iOS Development Create an object and access the instance variable