Search code examples
objective-cfoundation

What is the reason behind giving Underscore in private header files of apple


I have seen many .h ( Private API's ) of apple. Most of the variables / structures / enums / classes have _ as prefix.

#import <Foundation/NSValue.h>
#import <Foundation/NSObjCRuntime.h>

@class NSString;

typedef struct _NSRange {
    NSUInteger location;
    NSUInteger length;
} NSRange;

My question is,

What is reason behind giving underscore & typedef them again with proper one?


Solution

  • Objective-C has a globally open name space. It's important that all names be unique. In addition to the reasons given previously, Apple reserves all underscore names for itself. This will help prevent accidental name collisions.