Using enum datatype declared in another class in Objective C

No, if you define the enum in the source file instead of the header, then only that source file will be able to utilise the identifiers used in the enum. If you want to keep it “private” but usable by more than one source file, put it in a separate header and include this separate header in both source files.


This has nothing to do with classes. This is a feature of C.

If you define a type or an enum in a .h file, you can use it by importing it (#import) where you need it.

If you define your enum in a .c or .m file, only elements after that definition in the file can use it.

In your case, it appears that you need the same enum in two different files. Usage is to define that enum in a separate file, e.g., knownTypes.h and import that file in the two files using it: DataClass.m and TestClass.m.

If TestClass is for testing purpose, then your current organization is OK: enum is declared in DataClass.h and both DataClass.m and TestClass.m import DataClass.h.