Enums in delegate method declaration

kRiZ

I have an enum declared in the .h file as follows:

typedef enum {
   item1 = 0,
   item2,
   item3
} myEnum;

I want to use it in a delegate method signature in a view controller as follows:

@protocol myClassDelegate <NSObject>
- (void)myDelegateMethod:(enum myEnum)type;
@end

I have included the .h file in this view controller class.

Autocomplete does not suggest the enum when creating the above protocol and the compiler complains as well.

It works fine with using int instead of the enum in the signature. However, I'd like to know if there is/isn't a way of using the enum or if I'm doing something wrong.

I have gone through many posts but all of them were of normal methods.

EDIT:

ViewControllerA.h

#import <UIKit/UIKit.h>
#import "ViewControllerB.h"

typedef enum {
   item1 = 0,
   item2,
   item3
} myEnum;

@interface ViewControllerA : UIViewController <myClassDelegate>

@end

ViewControllerB.h

#import <UIKit/UIKit.h>
#import "ViewControllerA.h"

@protocol myClassDelegate <NSObject>
- (void)myDelegateMethod:(enum myEnum)type; // Autocomplete does not suggest the enums
                                            // Also, x-code gives warning: Declaration of 'enum myEnum' will not be visible outside of this functio
@end

@interface ViewControllerB : UITableViewController
@property (nonatomic, strong) id<myClassDelegate> delegate;
@end
Droppy

You have a circular header dependency (ViewControllerA.h imports ViewControllerB.h and vice versa).

Move the enum declaration into a common header file and import that wherever it's needed:

CommonTypes.h:

typedef enum {
   item1,
   item2,
   item3
} MyEnum;

ViewControllerA.h:

#import <UIKit/UIKit.h>
#import "ViewControllerB.h"

@interface ViewControllerA : UIViewController <myClassDelegate>
// I assume there is a reference to ViewControllerB here somewhere?
@end

ViewControllerB.h:

#import <UIKit/UIKit.h>
#import "CommonTypes.h"

@protocol myClassDelegate <NSObject>
- (void)myDelegateMethod:(MyEnum)type;
@end

@interface ViewControllerB : UITableViewController
@property (nonatomic, strong) id<myClassDelegate> delegate;
@end

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Where is declaration of invoke method in Delegate class?

From Dev

Where is declaration of invoke method in Delegate class?

From Dev

Sort enums in declaration order

From Dev

Trying to use a delegate method written in Objective-C in Swift is throwing "Cannot find protocol Declaration"

From Dev

Trying to use a delegate method written in Objective-C in Swift is throwing "Cannot find protocol Declaration"

From Dev

Delegate declaration in subclass incompatible with delegate in parent class

From Dev

Custom Delegate cannot find declaration

From Dev

cannot find protocol declaration for delegate

From Dev

Swift enums that call a method

From Dev

Using @class to get access to a delegate protocol declaration

From Dev

cannot find protocol declaration with my custom delegate

From Dev

Which is the correct/better way of Delegate declaration

From Dev

cannot find protocol declaration with my custom delegate

From Dev

Difference between different property declaration in the delegate case

From Dev

UIPageViewController delegate method not called

From Dev

Looking for subviewsDidChange delegate method

From Dev

Custom delegate method in Swift

From Dev

Delegate method not being called?

From Dev

Generic Method assigned to Delegate

From Dev

Logging for each method in "delegate"

From Dev

UITableView Delegate Method

From Dev

No overload for method matches delegate?

From Dev

willDisplayCell delegate method Swift

From Dev

Delegate Method is not called in Swift?

From Dev

What is this delegate method doing?

From Dev

Delegate method is not called (is nil)

From Dev

Generic Method assigned to Delegate

From Dev

UIPageViewController delegate method not called

From Dev

Passing a parameter to a delegate method

Related Related

  1. 1

    Where is declaration of invoke method in Delegate class?

  2. 2

    Where is declaration of invoke method in Delegate class?

  3. 3

    Sort enums in declaration order

  4. 4

    Trying to use a delegate method written in Objective-C in Swift is throwing "Cannot find protocol Declaration"

  5. 5

    Trying to use a delegate method written in Objective-C in Swift is throwing "Cannot find protocol Declaration"

  6. 6

    Delegate declaration in subclass incompatible with delegate in parent class

  7. 7

    Custom Delegate cannot find declaration

  8. 8

    cannot find protocol declaration for delegate

  9. 9

    Swift enums that call a method

  10. 10

    Using @class to get access to a delegate protocol declaration

  11. 11

    cannot find protocol declaration with my custom delegate

  12. 12

    Which is the correct/better way of Delegate declaration

  13. 13

    cannot find protocol declaration with my custom delegate

  14. 14

    Difference between different property declaration in the delegate case

  15. 15

    UIPageViewController delegate method not called

  16. 16

    Looking for subviewsDidChange delegate method

  17. 17

    Custom delegate method in Swift

  18. 18

    Delegate method not being called?

  19. 19

    Generic Method assigned to Delegate

  20. 20

    Logging for each method in "delegate"

  21. 21

    UITableView Delegate Method

  22. 22

    No overload for method matches delegate?

  23. 23

    willDisplayCell delegate method Swift

  24. 24

    Delegate Method is not called in Swift?

  25. 25

    What is this delegate method doing?

  26. 26

    Delegate method is not called (is nil)

  27. 27

    Generic Method assigned to Delegate

  28. 28

    UIPageViewController delegate method not called

  29. 29

    Passing a parameter to a delegate method

HotTag

Archive