在实现文件中声明接口(Objective-C)

时间:2022-09-07 08:34:41

In the last verson ox xCode (4.3) I've seen that prefdefined templates (such us Master/Detail template) in which the interface declaration is made in the .m file. For example, in the file MyFile.h there is:

在上一个verson ox xCode(4.3)中,我看到了在.m文件中进行接口声明的预定义模板(这样的us Master/Detail模板)。例如,在文件MyFile中。h:有

@interface MyFile

@property (nonatomic, retain) NSString *someProp;

@end

And in the MyFile.m file there is:

和MyFile。m文件有:

@implementation MyFile

@interface MyFile {
    NSString * anotherProp;
}

- (id) init...

Why it's made on this way? Why the anotherProp isn't declared into the MyFile.h file?

为什么要这样做?为什么没有在MyFile中声明另一个道具。h文件?

Thanks in advance

谢谢提前

1 个解决方案

#1


5  

Well its not declared this way but this way :-

它不是这样声明的,而是这样:-。

@interface ClassName() {

    Declarations;

}

Methods;

@end

These are called class extension.They are similar to categories but can be declared only in implementation of the class not in any other class.The use of extensions is to redeclare property that is public or readwrite , also declare newer ones , if needed.They simply allow you to declare properties and variables in places other than @interface so the name extensios.

这些被称为类扩展。它们类似于类别,但只能在类的实现中声明,而不是在其他类中。扩展的用途是重新声明公共属性或readwrite属性,如果需要,也声明更新的属性。它们只允许您在@interface之外的地方声明属性和变量,即extensios。

It was inrtoduced to tackle the problem with categories as they make the methods public and data hiding capability of classes is compensated but a class extension effectively extends the class’s primary interface which the declared methods have the same requirements as methods declared in the class’s oft public primary interface.

这是这是解决的问题类别,因为他们公开的方法和数据隐藏能力类补偿但类扩展有效地扩展了类的主要接口声明的方法有相同的需求作为主要方法中声明的类经常的公共接口。

#1


5  

Well its not declared this way but this way :-

它不是这样声明的,而是这样:-。

@interface ClassName() {

    Declarations;

}

Methods;

@end

These are called class extension.They are similar to categories but can be declared only in implementation of the class not in any other class.The use of extensions is to redeclare property that is public or readwrite , also declare newer ones , if needed.They simply allow you to declare properties and variables in places other than @interface so the name extensios.

这些被称为类扩展。它们类似于类别,但只能在类的实现中声明,而不是在其他类中。扩展的用途是重新声明公共属性或readwrite属性,如果需要,也声明更新的属性。它们只允许您在@interface之外的地方声明属性和变量,即extensios。

It was inrtoduced to tackle the problem with categories as they make the methods public and data hiding capability of classes is compensated but a class extension effectively extends the class’s primary interface which the declared methods have the same requirements as methods declared in the class’s oft public primary interface.

这是这是解决的问题类别,因为他们公开的方法和数据隐藏能力类补偿但类扩展有效地扩展了类的主要接口声明的方法有相同的需求作为主要方法中声明的类经常的公共接口。