What is the reason for providing Underscore in apple closed headers

I saw a lot of .h (Private API) for Apple. Most variables / structures / enumerations / classes have _ as a prefix.

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

@class NSString;

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

My question is:

What is the reason that you underline and type them again with the correct one?

+3
source share
4 answers

Objective-C has a globally open namespace. It is important that all names are unique. In addition to the reasons given earlier, Apple reserves all underscore names for itself. This will help prevent accidental name collisions.

+7
source

, / . , C , "filler".

+2

, . . , .. , , , Apple , .

+1

typedef struct _name {...} name GCC 2.0 , , , .

Apple, Apple , . Apple , , .

Unfortunately, many sample code projects were published on the Apple Developer website without going through the code and removing leading underscores from ivar names. This happens for two reasons, the main one being that developers working inside Apple have a habit of naming their variables this way, and another reason is that people looking at sample code projects really didn't really care about forced standard coding style.

+1
source

Source: https://habr.com/ru/post/1724442/


All Articles