1

I have a #define macros define in objective c files which i would like to access in my swift class, I have added the .h file import statements in my bridging header, but for some reason my swift class is not able to recognize my #define constants , Can anyone please suggest what is going wrong.

Max
  • 5,380
  • 6
  • 42
  • 66
  • 1
    `#define` is simply not available in swift, there are no macros. Take a look at http://stackoverflow.com/a/24326206/2442804 – luk2302 Jul 16 '16 at 21:15
  • #define is in my objective c file, I want to access those in swift , is there a way to do it , or do i have to write a complete new code for it to work ? – Max Jul 16 '16 at 21:20
  • probably the later one. – luk2302 Jul 16 '16 at 21:21
  • so how do i access them in swift ? – Max Jul 16 '16 at 21:23
  • "the later one" meaning you have to write new code. Just create a global function or constant – luk2302 Jul 16 '16 at 21:24
  • my app actually is a mixture of objc and swift code and there are many files in objc which uses #define, converting all of them newly is that the best approach ? – Max Jul 16 '16 at 21:33
  • Swift imports some "simple" macros as Swift constants. `#define CONST_A 1` can be imported, but `#define CONST_B (1+2)` cannot be. How's your macros? – OOPer Jul 16 '16 at 21:52
  • my macro in objc is #define IS_IPHONE_5S() (IS_IPHONE() && SCREEN_MAX_LENGTH == 568.0) – Max Jul 16 '16 at 21:54
  • 1
    those are bad macros to use anyway. Adopt autolayout. Do not write code that depends on device detection. – Paulw11 Jul 16 '16 at 22:02

0 Answers0