将@interface 放入 .m 文件的逻辑是什么? [英] What's the logic of putting @interface in .m file?

查看:52
本文介绍了将@interface 放入 .m 文件的逻辑是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
.h 和 .m 文件中 @interface 定义的区别
什么是@用于 iOS 5 项目的 .m 文件中的接口声明?

我见过这样的代码:

// In Header.h
@interface Header{}
@end

// In Header.m
@interface Header()
@end

我的问题是:

  1. 把它放在 2 个文件中有什么区别?
  2. 为什么在.h"文件中将{}放在类名之后,为什么在.m"文件中使用()"?

推荐答案

@interface MyClass(){
    NSInteger aInt;

}
@property(nonatomic,strong) NSString *name;
@end

是一个类扩展

使用现代编译器,这是一种很好的方法,可以将方法、变量和属性声明为仅在 MyClass 类中私有使用.

with modern compilers this is a great way, to decrale methods, ivars and properties only for private use in the class MyClass.

类扩展必须在主实现文件中声明(而不是在一个类别中).

Class extensions have to be declared in the main implementation file (not in a category).

所以你可以从头文件中隐藏实现细节,它们是私有的.

So you can hide implementation details from the header file, they are private.

这篇关于将@interface 放入 .m 文件的逻辑是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆