How to create global enum

2020-07-06 06:26发布

问题:

How to access enum through all classes. Let me explain:

enum
{
   BottomBackButtonNav = 0,
   BottomNextButtonNav,
   BottomSliderIncreaseNav,
   BottomSliderDcreaseNav,
   PageSwipeLeftNav,
   PageSwipeRightNav,
   NavFromThumbnailView,
   NavFromTOCView,
} NavigationType;

This enum is defined in my MainViewController's header and want to use it to all my views. How to do this, please guide.

Regards.

回答1:

You can define it in an header file (.h) and import it in each module you need



回答2:

You can also create a header file that holds all your enums and then import this header file in your projects .pch file (usually located in your Supporting Files folder).


This Prefix header uses the contents of this file and includes them on every source file. So it pretty much imports whatever headers that are set in the #ifdef __OBJC__ section to every file during compile time.



标签: objective-c