Comparison of similarities and differences between Black Horse programmer--oc and C language

Source: Internet
Author: User


1. File Description: Objective-c also uses header files, suffix. h, but uses. m (that is, message, other object-oriented programming languages also called method), as the suffix of the source file.
Using #import<> in Objective-c, instead of using #include<>,#import, ensures that the header file is included only once.
2. Where c is consistent: data types, expressions, various operators
Loops: For, while, does while, break, continue branch: If, else, switch
3.NSlog () function: similar to printf (), you want the console to output information. But it adds some features, such as timestamps. "Cocoa adds an NS prefix to all functions, constants, and type names. 】
4. The @ at the front of the double quotation mark indicates that the string in the double quotation mark should be treated as the nsstring element of the cocoa.

5. Boolean type bool: the value is yes,no;

6.%d indicates that the output integer%@ indicates that the output NSString type%s represents an array of output strings (char*);

7. Square brackets in objective-c: 1. Used to inform an object what to do.
2. The first item in square brackets is the object, and the remainder is the action you want the object to perform.
3. Notifies an object in Objective-c to perform some action, known as sending a message. (also called Call method)

8. Identifier ID: is a generic type that is used to represent objects of any kind.

9. class declaration @interface:

@interface Circle:nsobject//Defines an interface for the Circle class; NSObject represents the parent class.

{//The following are data members

Shapecolor FillColor;

Shaperect bounds;

}

Here is the method declaration

-(void) Setfillcolor: (Shapecolor) FillColor; The preceding short line indicates that this is the method declaration//Short line followed by the return type of the method//followed by the method name

The colon is followed by a parameter, where (Shapecolor) is the argument type and FillColor is the parameter name
-(void) SetBounds: (shaperect) bounds; -(void) draw; //minus is a normal function plus is a static function @end//END Declaration

Objective-c sees the @ symbol as an extension of the C language. The complete declaration of a class is as follows:
@interface Cclassa (Category): Cbaseclass<ia,ib ... >//Class name (category name): Parent class < protocol >
10. Class implementation @implementation


@implementation @implementation Circle
-(void) Setfillcolor: (Shapecolor) C

{
Fillcolor=c;

}
-(void) Draw

{

NSLog (@ "Drawing a circle at (%d%d)%d) in%@",

Bounds.x,bounds.y,bounds.width,bounds.height,colorname (Fillname));

}

@end


The Hidden object self corresponds to this in C. Self->fillcolor to access member variables.
11. Call the written class and class functions:
Creating a new object, using the default initialization function
Bank *bankdefault = [[Bank alloc] init]; Call Method:
[Bank addamount:1]; [Bank print]; To dispose of objects:
[Bankdefault free];
12.
Two parameters of the method:
-(void) Settire: (Tire *) Tire//Disclaimer

atindex: (int) index;

Use

[Car Settire:tire atindex:2];

http://www.itheima.com/

Comparison of similarities and differences between Black Horse programmer--oc and C language

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.