OGeek|极客世界-中国程序员成长平台

标题: ios - Objective-C 系统宏中的下划线命名约定 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 12:30
标题: ios - Objective-C 系统宏中的下划线命名约定

我对 Objective-C 宏中的命名约定很好奇。例如,以下代码是每个项目的预编译头文件(.pch 文件)中的标准代码

#import <Availability.h>

#ifndef __IPHONE_5_0
#warning "This project uses features only available in iOS SDK 5.0 and later."
#endif

#ifdef __OBJC__
    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
#endif

为什么 __IPHONE_5_0 的前缀是 2 个下划线,而 __OBJC__ 的前缀和后缀都是 2 个下划线?带前缀的下划线通常表示程序员不应该接触的系统内容。但是后缀下划线呢?谢谢!



Best Answer-推荐答案


我做了一些研究,在 Apple's "Coding Guidelines for Cocoa" 中找到了这个片段:

Note that macros defined by the compiler have leading and trailing double underscore characters. For example: __MACH__

关于ios - Objective-C 系统宏中的下划线命名约定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26684548/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4