Objective-C Language Features

Source: Internet
Author: User

Objective-C Language Features

1. Objective-C is based on the C language. It is a design language that adds extensions to the C language to create and operate objects.

2. Objective-C is a superset of ANSI-C that can be mixed with C and C ++ code.

3. It can be implemented on the basis of the existing C compiler without writing a new compiler. Objective-C on MAC systems generally uses the xcode compiler.

4. The namespace mechanism is not supported. Generally, the prefix is added to the category name. In the cocoa programming environment, all Mac OS X categories and functions are prefixed with "ns", such as nsstring and nsobject.

5. Operator Overloading is not supported. Only supportedSingle inheritance,Multi-inheritance is not allowed.

6. The biggest feature of object orientation isMessage transmissionModel, the object does not call methods, but transmits messages to each other.

7. inline functions are not supported.

Class definitions are generally written in. H files. Class implementations are written in. M files, for example:

Person.h#import<Foundation/Foundation.h>@interface Person:NSObject{@privateNSString *name;int age;}@property(noatomic,retain) NSString* name;-(void)setAge:(int)value;-(void)printInfo;@end


Person.m#import"Person.h"@implementation Person@synthesize name;-(int)age{    return age;}-(void)setAge:(int)value{    age = value;}-(void)printInfo{    NSLog(@"name:%@.\n",name);    NSLog(@"age:%d.\n",age);}@end


Test code in the main function:

Person *person = [[Person alloc] init];[person setName:@"Marry"];[person setAge:32];[person release];

In objective-C, a pair of brackets [] indicates message transmission. For example, person is the message receiver and setname is the message function.

Here

@property(noatomic,retain) NSString* name;

Is the attribute declaration corresponding to @ synthesize name in the. M file;

In this case, the system automatically generates the set and get methods. Of course, if you have defined set and get, the user-defined set and get will be called when the message is delivered, and the system will not be called.

Objective-C: bool

Typedef char bool;

# Define Yes 1

# Define no 0

Nil and nil and null

Nil built-in type pointer, null value assigned to the object

Null Value of Nil Class Object

Null Value 0


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.