1

I have always wondered, when you define something such as a string (or anything for that matter), why do people put a 'k' ahead of the defined name?

e.g. #define kHello = @"Hello"

What's that 'k' all about?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Josh Kahane
  • 16,765
  • 45
  • 140
  • 253

1 Answers1

2

I'm pretty sure the 'k' is short for constant. (Don't ask me why it's a k.)

Alyssa Ross
  • 2,169
  • 16
  • 26
  • the convention I prefer is `ALL_CAPS` – Dave Jun 09 '13 at 11:21
  • @Dave I like `ALL_CAPS` too, but a disadvantage of it is that with the `k` convention you can just type `k` in Xcode and see all of the constants available. – Alyssa Ross Jun 09 '13 at 11:22
  • Is that an advantage? Usually when you want a constant you want a specific one, not just to choose one at random from a really long list! (or, to put it another way, the name of the variable is more important than its type when you're trying to find it) – Dave Jun 09 '13 at 11:24
  • @Dave you might be looking for a constant but not know what it was called, in which case a list of constants could be very helpful. – Alyssa Ross Jun 09 '13 at 11:25