Li Hongqiang iOS Development Create an object and access the instance variable

Source: Internet
Author: User

//

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.