代码改变世界

iphone 常用预编译代码

2012-11-02 15:32  三戒1993  阅读(128)  评论(0)    收藏  举报

http://blog.sina.com.cn/u/2079395307  iphone和andorid开发博客

1.自定义DLog输出

#ifdef DEBUGLOG

#   define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);

#else

#   define DLog(...)

#endif


2.判断设备ios版本

#define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)

#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)


3.判断设备是否支持retina

#ifndef ImageShowcase_Utility_h

#define ImageShowcase_Utility_h

#define isRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640,960), [[UIScreen mainScreen] currentMode].size) : NO)

#endif


4.适配iphone5的屏幕

//adaptive iphone5 macro

#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640,1136), [[UIScreen mainScreen] currentMode].size) : NO)

#define iPhoneAppFrame [[UIScreen mainScreen] applicationFrame]

#define iPhoneScreenBounds [[UIScreen mainScreen] bounds]


5.Debug 标记

  /*!

   For debugging:

   Go into the "Get Info" contextual menu of your (test) executable (inside the "Executables" group in the left panel of XCode). 

   Then go in the "Arguments" tab. You can add the following environment variables:

   

   Default:   Set to:

   NSDebugEnabled                        NO       "YES"

   NSZombieEnabled                       NO       "YES"

   NSDeallocateZombies                   NO       "YES"

   NSHangOnUncaughtException             NO       "YES"

   

   NSEnableAutoreleasePool              YES       "NO"

   NSAutoreleaseFreedObjectCheckEnabled  NO       "YES"

   NSAutoreleaseHighWaterMark             0       non-negative integer

   NSAutoreleaseHighWaterResolution       0       non-negative integer

   

   For info on these varaiables see NSDebug.h; http://theshadow.uw.hu/iPhoneSDKdoc/Foundation.framework/NSDebug.h.html

   

   For malloc debugging see: http://developer.apple.com/mac/library/documentation/Performance/Conceptual/ManagingMemory/Articles/MallocDebug.html

   */

6. ARC宏定义

#ifndef MB_STRONG

#if __has_feature(objc_arc)

    #define MB_STRONG strong

#else

    #define MB_STRONG retain

#endif

#endif


#ifndef MB_WEAK

#if __has_feature(objc_arc_weak)

    #define MB_WEAK weak

#elif __has_feature(objc_arc)

    #define MB_WEAK unsafe_unretained

#else

    #define MB_WEAK assign

#endif

#endif


7.ARC (Automatic Reference Counting)

JMImageCache uses Automatic Reference Counting (ARC). If your project doesn't use ARC, you will need to set the -fobjc-arccompiler flag on all of the JMImageCache source files. To do this in Xcode, go to your active target and select the "Build Phases" tab. In the "Compiler Flags" column, set -fobjc-arc for each of the JMImageCache source files.




ARC (Automatic Reference Counting)

JMImageCache uses Automatic Reference Counting (ARC). If your project doesn't use ARC, you will need to set the -fobjc-arccompiler flag on all of the JMImageCache source files. To do this in Xcode, go to your active target and select the "Build Phases" tab. In the "Compiler Flags" column, set -fobjc-arc for each of the JMImageCache source files.

ARC (Automatic Reference Counting)

JMImageCache uses Automatic Reference Counting (ARC). If your project doesn't use ARC, you will need to set the -fobjc-arccompiler flag on all of the JMImageCache source files. To do this in Xcode, go to your active target and select the "Build Phases" tab. In the "Compiler Flags" column, set -fobjc-arc for each of the JMImageCache source files.

版权声明:本文为博主原创文章,未经博主允许不得转载。