Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Obj-C enum redefinition error

typedef enum {
    artists = 0,
    artists_songs = 1,
    artist_albums = 2,
    albums = 3,
    album_songs = 4,
    tags = 5,
    tag = 6,
    tag_artists = 7,
    tag_albums = 8,
    tag_songs = 9,
    songs = 10,
    song = 11,
    playlists = 12,
    playlist = 13,
    playlist_songs = 14,
    search_songs = 15
} Methods;

typedef enum {
    artists = 0,
    albums = 1,
    songs = 2,
    tags = 3,
    playlists = 4    
} ReturnTypes;

I keep getting an error on the artists = 0 line for ReturnTypes, saying that artists has been re-declared. I'm not sure what the syntax error on this is. Any ideas?

like image 882
Ryan Copley Avatar asked Apr 30 '13 16:04

Ryan Copley


1 Answers

The syntax error is that artists is being redeclared! You've declared it once in the first enum, now you're trying to declare it again in the second line. These enums are not separate types; they are just lists of constants. You can't have two constants called artists.

This is why enums in Cocoa have obnoxiously long boring names, such as UITableViewCellStyleDefault. It is so that they won't clash with one another. You should do the same, e.g. MyMethodsArtists vs. MyReturnTypesArtists.

like image 194
matt Avatar answered Nov 20 '22 18:11

matt