I have a DataClass.h
@interface DataClass : NSObject
{
}
enum knownTypes
{
type1 = 0,
type2,
type3,
UnknownType = -1
};
Is there a way I can specify knownTypes in .m file and access from other class.
This is Util class i am creating, hence don’t want to create an object to access the values in this class.
for ex: in TestClass.m , by importing DataClass.h , now i can use the enum values as type1,type2.. but if i declare the enum data in DataClass.m , i could not use those enum values.
This has nothing to do with classes. This is a feature of C.
If you define a type or an enum in a
.hfile, you can use it by importing it (#import) where you need it.If you define your enum in a
.cor.mfile, 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.hand import that file in the two files using it:DataClass.mandTestClass.m.If
TestClassis for testing purpose, then your current organization is OK: enum is declared inDataClass.hand bothDataClass.mandTestClass.mimportDataClass.h.