Object-C

Objective-C: A Superset of C
.h header files. it contains type fucntion constant declarations.
.m source files.contain both Object-C and C code.
.mm like above.It contain C++ code in addition to Object-C and C code.
Classes


@interface Myclass:NSObject
{
  int count;
  id  data;
}
-(id)initWithString:(NSString*)aName; //Method declarations.
+(MyClass*)CreateMyClassWithString:(NSString*)aName;//Method declarations.
@end

Notes:
MyClass: class name
NSObject: Parent class name .Cocoa's base class.
int count; | Member variable declarations
id  data;  |


Objective-C supports both strong and weak typing for variables containing objects. Strongly typed variables include the class name in the variable type declaration. Weakly typed variables use the type id for the object instead.
eg:
MyClass *myObject1;  // Strong typing

id       myObject2;  // Weak typing
The id type implies a pointer.

Methods and Messaging
A class in Objective-C can declare two types of methods: instance methods and class methods. An instance method is a method whose execution is scoped to a particular instance of the class. In other words, before you call an instance method, you must first create an instance of the class. Class methods, by comparison, do not require you to create an instance, but more on that later.

The declaration of a method consists of the method type identifier, a return type, one or more signature keywords, and the parameter type and name information.

Declared Properties
Declared properties are a convenience notation used to replace the declaration and, optionally, implementation of accessor methods.
You include property declarations with the method declarations in your class interface. The basic definition uses the @property compiler directive, followed by the type information and name of the property. You can also configure the property with custom options, which define how the accessor methods behave. The following example shows a few simple property declarations:

@property BOOL flag;

@property (copy) NSString *nameObject;  // Copy the object during assignment.

@property (readonly) UIView *rootView;  // Declare only a getter method
Each readable property specifies a method with the same name as the property. Each writable property specifies an additional method of the form setPropertyName:, where the first letter of the property name is capitalized.
In your class implementation, you can use the @synthesize compiler directive to ask the compiler to generate the methods according to the specification in the declaration:

@synthesize flag;

@synthesize nameObject;

@synthesize rootView;

Strings

As a superset of C, Objective-C supports the same conventions for specifying strings as C. In other words, single characters are enclosed by single quotes and strings of characters are surrounded by double quotes. However, Objective-C frameworks typically do not use C-style strings. Instead, they pass strings around as NSString objects.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值