Configure and access Typedef enumerations

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

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

Then I announced the following:

Weather weather;

Then he made an accessory:

@property Weather weather;

And synthesized it.

My question is, how can I use this in another class without failing it? I have imported the title for MainView. I tried using it as follows:

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

[myView setWeather: CLEAR];

It does not throw me any errors in Xcode, but it crashes when running the code, saying:

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

Am I doing something wrong here?

+3
source share
3 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;
+6
source
+1

* Weather* weather. weather , .

+1
source

Source: https://habr.com/ru/post/1771557/


All Articles