【问题标题】:How should I write words with dash in camelCase?我应该如何在 camelCase 中用破折号写单词?
【发布时间】:2013-04-22 06:57:41
【问题描述】:

例如:Meta-information

metaInfornationmetainformationmetainfo?

getMetainfogetMetaInfogetMetaInformation?

objective-c 风格怎么样?

【问题讨论】:

  • "get" 不应用作非常特殊情况之外的方法前缀。

标签: objective-c camelcasing code-standards


【解决方案1】:

我个人是 camelCase 的粉丝,没有缩写。所以我会使用metaInformationmetaInfo 也很好,因为它是一个非常常见的缩写。
我不喜欢printAttr 或类似的东西。

Apple 在该主题上有 docs,描述了约定。

请注意,您应该在您的 getter 中使用 get

当您应用这些约定时,您有很多机会(例如Key-Value-Coding)。

【讨论】:

    【解决方案2】:

    如果它是一个属性,那么你会想要使用metaInformationmetaInfo,它会生成-metaInformation-metaInfo 的getter。切勿在方法名称中使用 get。

    【讨论】:

    • 大写 I 是可以选择的 ;)
    • @max_ 来自docsIf the method returns an attribute of the receiver, name the method after the attribute. The use of “get” is unnecessary, unless one or more values are returned indirectly.
    • 是的,关于 obj-c 中的“get”的一切都很清楚 :),我举了一个通用的例子,谢谢!我对破折号旁边的大写或小写选择更感兴趣。
    猜你喜欢
    • 1970-01-01
    • 2019-03-25
    • 2017-02-24
    • 1970-01-01
    • 2021-09-27
    • 1970-01-01
    • 2016-03-26
    • 2018-04-10
    • 1970-01-01
    相关资源
    最近更新 更多