Objective C - Why do constants start with k

后端 未结 6 925
栀梦
栀梦 2020-12-05 04:10

Why do constants in all examples I\'ve seen always start with k? And should I #define constants in header or .m file?

I\'m new to Objective C, and I don\'t know C. I

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-05 04:41

    k for "konvention". Seriously; it is just convention.

    You can put a #define wherever you like; in a header, in the .m at the top, in the .m right next to where you use it. Just put it before any code that uses it.

    The "intro to objective-c" documentation provided with the Xcode tool suite is actually quite good. Read it a few times (I like to re-read it once every 2 to 5 years).

    However, neither it nor any of the C books that I'm aware of will answer these particular questions. The answers sort of become obvious through experience.

提交回复
热议问题