Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maximum length of class name in objective-c

Tags:

objective-c

what is the maximum length of a class name in objective-c? I could not find any hints in the xcode doc-sets and google was no help either.

I am currently writing some runtime helpers, and it would be nice to know if my char-buffers for the type-encoding are big enough.

like image 772
Jonathan Cichon Avatar asked Sep 01 '25 10:09

Jonathan Cichon


2 Answers

Since Objective C is not a standardized programming language this question can't really be answered. But it rather depends on what your compiler supports. I guess the major Objective C compilers (Clang/LLVM, GCC) support all lengths of class names. To find out you would have to have a look at their sources. But since they are both written in C++ they will probably utilize std:string and be therefore length independent.

I gave it a try and tried to compile a project with a 100.000 character class name using clang/llvm in Xcode, which worked perfectly fine.

So your buffers are likely not to be big enough.

like image 172
SIGKILL Avatar answered Sep 04 '25 10:09

SIGKILL


I don't believe there is a hard limit to the class name size, why would there be?

With Obj-C being run on top of C, it would follow their standards. Identifiers in C do not have a maximum length, as identified in the question "Max identifier length"

It is very unlikely for you to come across a class name greater than 100 characters, but you could always have bigger buffers to be safer.

like image 20
WDUK Avatar answered Sep 04 '25 11:09

WDUK