美文网首页
iOS编程细节

iOS编程细节

作者: 单线程Jack | 来源:发表于2019-07-26 11:00 被阅读0次

    1、判断文件是否存在,再导入使用,避免文件不存在的情况;

    #if __has_include(<unistd.h>)
    # include <unistd.h>
    #elif __has_include(<io.h>)
    # include <io.h>
    #else
    # error "Insane system"
    #endif
    
    #if __has_include(<YYModel/YYModel.h>)
    FOUNDATION_EXPORT double YYModelVersionNumber;
    FOUNDATION_EXPORT const unsigned char YYModelVersionString[];
    #import <YYModel/NSObject+YYModel.h>
    #import <YYModel/YYClassInfo.h>
    #else
    #import "NSObject+YYModel.h"
    #import "YYClassInfo.h"
    #endif
    

    2、FOUNDATION_EXPORT与#define 哪个来定义常量更好?

    首先看看 苹果的定义

    NSObjCRuntime.h中的写法:

    #if defined(__cplusplus)
    #define FOUNDATION_EXTERN extern "C"
    #else
    #define FOUNDATION_EXTERN extern
    #endif
     
    #if TARGET_OS_WIN32
     
        #if defined(NSBUILDINGFOUNDATION)
            #define FOUNDATION_EXPORT FOUNDATION_EXTERN __declspec(dllexport)
        #else
            #define FOUNDATION_EXPORT FOUNDATION_EXTERN __declspec(dllimport)
        #endif
     
        #define FOUNDATION_IMPORT FOUNDATION_EXTERN __declspec(dllimport)
     
    #else
        #define FOUNDATION_EXPORT  FOUNDATION_EXTERN
        #define FOUNDATION_IMPORT FOUNDATION_EXTERN
    #endif
    

    相关文章

      网友评论

          本文标题:iOS编程细节

          本文链接:https://www.haomeiwen.com/subject/vdlrrctx.html