CGFloat与float的区别
查看CGFloat的定义就会发现
typedef CGFLOAT_TYPE CGFloat;
#if defined(__LP64__) && __LP64__
# define CGFLOAT_TYPE double
# define CGFLOAT_IS_DOUBLE 1
# define CGFLOAT_MIN DBL_MIN
# define CGFLOAT_MAX DBL_MAX
#else
# define CGFLOAT_TYPE float
# define CGFLOAT_IS_DOUBLE 0
# define CGFLOAT_MIN FLT_MIN
# define CGFLOAT_MAX FLT_MAX
#endif
不难发现CGFloat其实是double与float的结合体,在64位系统上,CGFloat是double类型,在32位系统上是float类型;
FOUNDATION_EXPORT与#define的区别
#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
仔细看这段代码就知道,FOUNDATION_EXPORT的作用相当于extern,define不会对所定义的内容进行检查,所以具体用法也是不一样的。
一般情况下FOUNDATION_EXPORT的用法
xxx.h
FOUNDATION_EXPORT NSString *const USERNAME;
FOUNDATION_EXPORT int PASSWORD;
xxx.m
NSString *const USERNAME = @"user_name";
int PASSWORD = 123;
网友评论