Why doesn't Xcode recognize a typedef from a header that is correctly imported?

I used to have a class with a name Constants. It was like this typedef:

typedef enum visible_thing {

    BACKGROUND,
    BACKGROUND_COLOR,
    MAIN_WINDOW

} VISIBLE_THING;

And my life was rosy! I imported "Constants.h" wherever I needed to access this type, and it all worked.

Then I decided to blow up the class Constants. I took a typedef and put it in another class, let’s name it for clarity OtherClass. I went through and changed all imports Constants.hto imports. OtherClass.hEverything that I did, I did not touch other code. And now everything is broken!

Techniques that worked perfectly with Constantsnow give me this error: Parse Issue - Expected a type. What the heck? I really hope that someone has this

: , , , , . , , , # . # import, - . Arg. !

+6
4

, , , , . -, .

, , , .

, . :

#import "OtherClass.h"

@interface InnerClass

// uses typedef from OtherClass

@end



@interface MainClass

// uses typedef from OtherClass

@end

:

#import "OtherClass.h"

@interface InnerClass

// uses typedef from OtherClass

@end

#import "OtherClass.h" //<--without this, MainClass won't recognize the typedef 

@interface MainClass

// uses typedef from OtherClass

@end

, - , , , . .

0

" ", , . :

:

#import "B.h"

typedef enum {
    SomeEnumA
} SomeEnum;

@interface A : NSObject

@end

B.h:

#import "A.h"

@interface B : NSObject

- (void) func:(SomeEnum)arg;

@end

SomeEnum, B.h - A.m( A.h). , A.h B.h, A.h. , B.h A.h, .

, SomeEnum.h.

+8

, , , , , - , , , .

. , :

  • InnerClass, , .
  • typedef ( ), , .
  • .h OtherClass.h, , - .
  • , , .

I think it depends on what your project, if it is just something small and fast, that you want to work, it probably does not matter, but if it is a larger project, and you will see that your the code base is expanding, or if this is what other coders are working on, I will try to understand what is happening here.

+1
source

I just stumbled upon this while trying to create a Framework. Xcode did not like the fact that typedef is defined over an interface. Not sure why this is so, but it is fixed.

So I changed my with:

typedef enum {
   MyOption1,   // option 1.
   MyOption2,   // option 2.
}MyOption;

@interface MyClass : NSObject

@property (strong, nonatomic) NSString *myString;

@end

so that:

@interface MyClass : NSObject

typedef enum {
   MyOption1,   // option 1.
   MyOption2,   // option 2.
}MyOption;

@property (strong, nonatomic) NSString *myString;

@end
0
source

All Articles