在用@interface声明类之后,可以使用@implementation进行实类的实现。类的实现的具体语法如下:
- @implementation 类名
- 方法实现代码;
- @end;
实例:
- @implementation Person
- - (NSString*) name {
- return name;
- }
- - (int) age {
- return age;
- }
- - (void) setName: (NSString*) input {
- name = input;
- }
- - (void) setAge: (int) input {
- age = input;
- }
- @end;
类的实现代码以@implementation开始,以@end结束。
这部分代码通常都是放在.m文件中。
本文详细介绍了Objective-C中如何使用@implementation关键字来实现类的方法。通过具体的示例代码展示了类的各种方法,包括属性的get和set操作是如何被实现的。
3604

被折叠的 条评论
为什么被折叠?



