在MonoTouch中实现#define和#ifdef

时间:2012-06-13 13:06:05

标签: c# objective-c xamarin.ios

我是monoTouch的新手。我在Objective-C中有一个名为“TargetConditions.h”的文件。我正在尝试使用“TargetConditions.h”中的#define衍生物。但是,我无法将这些东西带入MonoTouch。这是事情清单,

#define TARGET_OS_MAC 1
#define TARGET_OS_WIN32 0
#define TARGET_OS_UNIX 0
#define TARGET_OS_EMBEDDED 0
#define TARGET_OS_IPHONE 1 
#define TARGET_IPHONE_SIMULATOR 1

#ifdef __MACH__
#define TARGET_RT_MAC_MACHO 1
#define TARGET_RT_MAC_CFM 0
#else
#define TARGET_RT_MAC_MACHO 0
#define TARGET_RT_MAC_CFM 1
#endif

如何将所有#define值集成到MonoTouch中? 请帮帮我。 提前谢谢。

1 个答案:

答案 0 :(得分:2)

您可以用类中的常量定义替换它们。

public const int TARGET_OS_MAC = 1; 
public const int TARGET_OS_WIN32 = 0; 
public const int TARGET_OS_UNIX = 0; 
public const int TARGET_OS_EMBEDDED = 0; 
public const int TARGET_OS_IPHONE = 1;  
public const int TARGET_IPHONE_SIMULATOR = 1; 

#if __MACH__ 
    public const int TARGET_RT_MAC_MACHO = 1; 
    public const int TARGET_RT_MAC_CFM = 0; 
#else 
    public const int TARGET_RT_MAC_MACHO = 0; 
    public const int TARGET_RT_MAC_CFM = 1; 
#endif