9

I defined a NS_ENUM below in another file:

typedef NS_ENUM (NSUInteger, LinkPlatformType){
    LinkPlatformTypeEmail = 1,
    LinkPlatformTypeFacebook,
    LinkPlatformTypeGoogle
};

When I try to do a switch case:

- (void)linkWithType:(LinkPlatformType)linkType {
    switch (linkType) {
        case LinkPlatformTypeGoogle:
            break;
        case LinkPlatformTypeFacebook:
            break;
        default:
            break;
    }
}

I am getting a build error: Reference to LinkPlatformTypeGoogle is ambiguous. Reference to LinkPlatformTypeFacebook is ambiguous.

Updates:

The file defines.h which i defined the enum is in for example Target 1, And there is a Class StoreClass which import this defines.h file. And the StoreClass.m Target Membership I have set as multiple targets: Target 1 and Target 2. So after I do this, the Reference to LinkPlatformTypeFacebook is ambiguous appeared. Will this be the reason?

yong ho
  • 3,892
  • 9
  • 40
  • 81
  • 1
    Did you try with a different naming for the enum? My best guess it's that it might be just a naming conflict and the compiler does not know what to reference. – Vlad May 27 '15 at 09:02
  • 1
    I tried the same code as yours with new project..I'm not getting any error as such, just to verify have you import file? and yes I put the NS_ENUM in defines.h file which is header file. – Rahul Shirphule May 27 '15 at 09:06
  • @Vlad I checked twice. There is no naming conflict. I only defined one in my project. – yong ho May 27 '15 at 09:19
  • @RahulShirphule I did import the file otherwise it will be another kind of warning. – yong ho May 27 '15 at 09:20
  • Maybe try to go through all three possible value in the switch, you just handled 2 out of three (although I see you have the default there) ... – Vlad May 27 '15 at 09:22
  • @Vlad I did go through all the value in switch. Still the same error. – yong ho May 27 '15 at 09:30
  • can you please show us how do you invoke `linkWithType:` method? – x4h1d May 27 '15 at 09:41
  • @x4h1d Sure. `[[LinkHelper sharedHelper] linkWithType:LinkPlatformTypeGoogle]`; – yong ho May 27 '15 at 09:44
  • my best guess is, you have multiple imports of `defines.h` file. Try moving that ENUM definition to `LinkHelper` class only. – x4h1d May 27 '15 at 09:52
  • @x4h1d There are many places that I need the enum. If I move the enum definition to a class only. It will not work. – yong ho May 27 '15 at 09:59
  • Did you check this http://stackoverflow.com/questions/25378474/reference-to-x-is-ambiguous – Anupam May 27 '15 at 10:02
  • When you need that ENUM you will also need this `LinkHelper` class too, right? so you can define it here. Or find a common class to import `defines.h`. – x4h1d May 27 '15 at 10:05
  • @Anupam I tried. Not helping. – yong ho May 28 '15 at 01:13
  • http://stackoverflow.com/questions/31199442/reference-to-is-ambigous-error-in-xcode/41765279#41765279 – Mohit Tomar Jan 20 '17 at 13:54

1 Answers1

7

Changing the import from

#import "SwipeView.h"

to

@import SwipeView;

worked for me

Fraser
  • 953
  • 11
  • 21
  • My class was in a module (subproject) so I tried to import @import MainModule.Folder where my view lives instead of the .h implementation and it worked, thank you! – Boda Jan 27 '17 at 12:38
  • It works for me with FBSDKLoginManager in FBSDKCoreKit 4.28.0 – Yao Li Nov 13 '17 at 18:22