嗨,我有这个头文件:
- #import <Foundation/Foundation.h>
- @interface PCConstants : NSObject
- extern NSString *const kPCUserProfileKey;
- extern NSString *const kPCUserProfileNameKey;
- extern NSString *const kPCUserProfileFirstNameKey;
- extern NSString *const kPCUserProfileLocationKey;
- extern NSString *const kPCUserProfileGenderKey;
- extern NSString *const kPCUserProfileBirthDayKey;
- extern NSString *const kPCUserProfileInterestedInKey;
- @end
执行:
- #import "PCConstants.h"
- @implementation PCConstants
- NSString *const kPCUserProfileKey = @"profile";
- NSString *const kPCUserProfileNameKey = @"name";
- NSString *const kPCUserProfileFirstNameKey = @"firstname";
- NSString *const kPCUserProfileLocationKey = @"location";
- NSString *const kPCUserProfileGenderKey = @"gender";
- NSString *const kPCUserProfileBirthDayKey = @"birthday";
- NSString *const kPCUserProfileInterestedInKey = @"interestedIn";
- @end
当我在.pch文件中导入头文件时,我可以在任何地方访问常量.但我试着了解发生了什么.
我从不为此对象分配init,因此它们不能是实例常量.所以常量必须是“类对象常量对吗?但我认为类对象不能包含数据.
谁能解释一下?