Lan Yi First Practice day, preview Objec-c basic concept

Source: Internet
Author: User

Today is practice day, more than nine came to the classroom, sunshine, or mood, my Mac notebook has a kind of excitement.

I looked at the basics in the morning, and the notes were re-organized once again. I closed the cloud notes I have learned the code to knock myself again, although very basic things but found that if you do not knock a few times it is easy to forget

Let's organize the code and comments for today's practice.

Experience:

!! If you want to create an object in four steps,

1, determine the method name

2, determine if the physical parameters

3, determine whether there is a return value type

4, determine the type of method, the return value of the instance, and the exact method or class method

The difference between a class method and an object method

1, the object method must use the object invocation

class method to be called with the class name

2, the property can be called in an object method

Class method can not call property

3, application scenarios for class methods

If a property is not used in a method, it is best to use a class method, which performs more efficiently than the object method.

@interface Iphone:nsobject//interface representative declares a class

{

@public//A common variable

int size;

int SID;

int weigh;

float color;

}

-(void) about; No return value no parameter

-(int) SendMessage: (nsstring*) nit;//has a return value with parameters

-(nsstring*) didmessage; There is a return value no parameter type

Implementation of the class, including methods and functions

@implementation the implementation of the iphone//class, implementation

-(void) about{

NSLog (@ "ooo");

}

-(int) call:(int) num{

NSLog (@ "Call%d", num);

return 1;

}

-(nsstring*) didmessage{

return @ "FDF";

}

-(int) SendMessage: (nsstring*) nit{

NSLog (@ "SADSFSFSF", nil);

return 2;

} @end

Main function

int main (int argc, const char * argv[]) {

@autoreleasepool {

iphone*pp= [iphone new];

pp->color=2.1;

pp->sid=22;

NSLog (@ "%f,%d", Pp->color,pp->sid);

[pp about];

[pp call:12323123];

[pp Didmessage];

If there is a return value, the main function wants to call the method output return, need to find a new parameter of the same type to catch the return value, for example, here want to output didmesssage content will be used Nssstring*uu catch, and then in the output NSLog (@ "" ", UU)

NSString *uu=[pp didmessage];;

NSLog (@ "%@", UU);

}

return 0;

}

Lan Yi First Practice day, preview Objec-c basic concept

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.