
大部分时候我们是一个文件对应一个class这样写,偶尔例外,比如嵌套model,我们会把这个model及它所包含的小model都写在一个文件里(当然这个也要视情况而定,并非任何时候写在同一个文件里都一定比分开写更好)。
还比如系统的UIAlertController,也是将UIAlertAction
和UIAlertController
写到了同一个文件中:

我觉得苹果的这种style还是值得借鉴滴。
下面就由我来现身说法。

如图:

里面有个选项栏模块:

这个选项栏肯定是要剔出来单独封装的,姑且称之为:XXXSegementView
,封装的过程中发现这几个带角标的按钮也比较有个人特色,所以干脆弄个自定义button:XXXSegementButton
。
因为XXXSegementButton
与XXXSegementView
是紧密关联的,所以我将XXXSegementButton
写在了XXXSegementView
文件里。
还因为这个XXXSegementButton
仅在此处使用,所以用filePrivate
关键字来修饰它。


网友评论