Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Macro condition for iOS and OSX code

I need to support iOS and OSX in my shared library, whats the best Macro / Practise for conditioning iOS and OSX code

the bellow code doesn't work for some reason :/

- (NSString *)hostName {
    #ifdef TARGET_OS_IPHONE
        return [[UIDevice currentDevice] name];
    #elif TARGET_OS_MAC
        return [[NSHost currentHost] localizedName];
    #endif
}
like image 541
Peter Lapisu Avatar asked Jan 18 '15 18:01

Peter Lapisu


People also ask

Why can't I see Macro's in Excel on my iPad?

Unfortunately excel for IOS devices (iPad, Iphone etc.) doesn't support this function (yet). If you really need the macro's to function it is advised to open the file within a windows or osx version of excel. You can also recognize an excel file with macro's to the extension, which is xlsm (instead of.xls or xlsx).

How do I open a macro file in Excel on iOS?

Unfortunately excel for IOS devices (iPad, Iphone etc.) doesn't support this function (yet). If you really need the macro's to function it is advised to open the file within a windows or osx version of excel. You can also recognize an excel file with macro's to the extension, which is xlsm (instead of .xls or xlsx). Good luck!

What is the-malign-mac68k macro in Mac OS X?

It is defined by default when you're compiling code for PowerPC architecutres. It is not defined when you use the -malign-mac68k compiler switch, nor is it defined on Intel architectures. This macro is defined if Mach system calls are supported. This macro is defined in any Apple computer.

What is macro in Excel?

I don't know if you know about 'macro's' but it is a code in VBA (Visual Basic for Applications) which expands the use of Excel. I see you are using an iPad to open the file and that is where the problem kicks in.


1 Answers

Two issues:

  1. Use #if rather than #ifdef
  2. Check TARGET_OS_IPHONE first since TARGET_OS_MAC is defined to 1 for both platforms

See: Which conditional compile to use to switch between Mac and iPhone specific code?

like image 176
EricS Avatar answered Oct 21 '22 21:10

EricS