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