Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typedef enum setting and accessing

I have this before the interface declaration in my MainView.h header.

typedef enum { UNKNOWN, CLEAR, NIGHT_CLEAR, CLOUDY, NIGHT_CLOUDY } Weather;

Then I declared it like this:

Weather weather;

Then made an accessor:

@property Weather weather;

And synthesized it.

My question is, how can I use this in a different class without it crashing? I've imported the header for MainView. I tried to use it like this:

MainView* myView = (MainView*)self.view;

[myView setWeather: CLEAR];

It doesn't throw me any errors in Xcode, but it crashes when the code is run, saying:

-[UIView setWeather:]: unrecognized selector sent to instance *blah*

Am I doing something wrong here?

like image 920
sudo rm -rf Avatar asked May 13 '26 13:05

sudo rm -rf


2 Answers

'Weather' is a type not a variable.

So, you want something like this:

Weather theWeather = [mainView weather];
if (theWeather == CLEAR)
{
<do something>
}

Where MainView has ivar:

 Weather weather;
like image 68
westsider Avatar answered May 16 '26 13:05

westsider


You have to remove the * in Weather* weather. weather has to be an integer, not a pointer.

like image 25
Rits Avatar answered May 16 '26 13:05

Rits