I have two objects: NavButton, visible on each ViewController and a particular ViewController. NavButton should know, which kind of ViewController is asking for it and hide unneeded buttons. I consider implementing this as passing an enum from ViewController to NavButton.
I have two questions on this:
1. Where should I declare enum?
2. How to make enum visible in all of the ViewControllers, so, each VC could access NavButton's property as: self.navButton.kind = bigButton;
Asked
Active
Viewed 682 times
0

Richard Topchii
- 7,075
- 8
- 48
- 115
-
2Put the enum in a .h file that each view controller can import. – rmaddy Aug 07 '14 at 22:55
-
What template should I use to create that .h file? As usual class? Is it OK to put that file to prefix.pch? – Richard Topchii Aug 07 '14 at 22:57
-
1Template? You don't need a template. Just a clean .h file with the enum. – rmaddy Aug 07 '14 at 22:58
-
And is it OK to put in prefix? – Richard Topchii Aug 07 '14 at 23:00
-
2See also: http://stackoverflow.com/questions/7912222/objective-c-typedef-enum-in-global-constants-file – Wain Aug 07 '14 at 23:00
1 Answers
1
Just use the C header template + the nsenum macro expansion and voila!
//
// Header.h
// Test
//
// Created by Yours Truly on 8/7/14.
// Copyright (c) 2014 Adam Christopher Smith. All rights reserved.
//
#ifndef Test_Header_h
#define Test_Header_h
typedef NS_ENUM(NSUInteger, MyEnum) {
MyEnumValueA,
MyEnumValueB,
MyEnumValueC,
};
#endif
If I have a lot of these and they are used by different parts of the app, I tend to stick quite a few into one file (maybe, Types.h) and put that into my pch. Quite acceptable IMO.

Acey
- 8,048
- 4
- 30
- 46