Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Valid characters in a class name in Objective-C

Tags:

objective-c

What is the set of valid characters for an Objective-C class?

Of course the basic naming conventions of letters, numbers and underscore all work, but I'm looking for a special character to avoid naming conflicts.

The $ symbol seems to work, but I could not find any documentation. The language reference does not mention it.

Any other? Any "official" document I can refer to?

like image 585
Marcos Crispino Avatar asked Mar 14 '14 13:03

Marcos Crispino


2 Answers

Historically, Objective-C compiler has been based on GNU C compiler, which allowed dollar signs in identifiers as an extension. As far as I know, this is the only exception to the rule of naming identifiers with sequences of letters, digits, and underscores that do not start in a digit.

Since Apple switched to a different toolchain for their compilers, it appears that the dollar sign is kept for backward compatibility. I would avoid using it in my new code, especially since Apple is not advertising it as a feature.

like image 50
Sergey Kalinichenko Avatar answered Nov 15 '22 20:11

Sergey Kalinichenko


At compile time, the set of characters is whatever the C/C++ compiler accepts as an identifier.

At runtime, anything UTF-8 goes.

like image 20
Greg Parker Avatar answered Nov 15 '22 18:11

Greg Parker