Objective-C 中类扩展的正确文件命名约定是什么? [英] What is the proper file naming convention of class extension in Objective-C?

查看:39
本文介绍了Objective-C 中类扩展的正确文件命名约定是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的班级编写单元测试.它具有在类扩展中声明的私有属性.现在,我想在我的单元测试中提供对其中一些属性的访问,因此我必须从实现文件中提取类扩展到一个单独的头文件中,我可以在我的单元测试中导入它.当类扩展名与实现 (.m) 分离时,类扩展名的正确文件命名约定是什么?

I'm writing unit tests for my class. It has private properties declared in the class extension. Now, I would like to provide access some of these properties in my unit tests, hence I have to extract the class extension from the implementation file into a separate header file that I can import in my unit tests. What is the proper file naming convention of class extension when it's separated from the implementation (.m)?

// MyClass.h
@interface MyClass : NSObject
@end

// MyClass.m
@implementation MyClass
@end

// MyClass+???.h
@interface MyClass()

@property (nonatomic, strong) NSString *myString;

@end

推荐答案

Objective C 没有标准的代码约定.Apple 的文档只描述了几个简单的时刻.最常用的方法是使用

There is no standard code convention for Objective C. Apple's documents describe only few simple moments. The most common approach is to use

MyClass_Private.h

用于扩展和

MyClass+Private.h

用于类别.

这篇关于Objective-C 中类扩展的正确文件命名约定是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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