2017-07-14 28 views
0

比如我在看CHMutableDictionary.h.h文件中的@interface后的{}是什么意思?

@interface CHMutableDictionary : NSMutableDictionary { 
    CFMutableDictionaryRef dictionary; // A Core Foundation dictionary. 
} 

- (id) initWithCapacity:(NSUInteger)numItems; 

- (NSUInteger) count; 
- (NSEnumerator*) keyEnumerator; 
- (id) objectForKey:(id)aKey; 
- (void) removeAllObjects; 
- (void) removeObjectForKey:(id)aKey; 
- (void) setObject:(id)anObject forKey:(id)aKey; 

@end 

它花括号CFMutableDictionaryRef dictionary。但在Objective-C guide Properties Control Access to an Object’s Values它没有使用{}提及任何在接口

@interface Person : NSObject 

@property NSString *firstName; 
@property NSString *lastName; 

@end 

所以我只是想知道什么的.h文件接口在{}定义的变量的意思。

回答

2

您在花括号中声明了实例变量。

但是把它们放在.h文件中是不好的形式。实例变量应该是私有的,而不是公共的。所以他们不属于公共的.h文件。

有很多旧的Objective-C代码不遵循这些更现代的约定。不要使用那些过时的惯例编写新的代码。

请参阅https://stackoverflow.com/a/13263345/1226963了解一些现代示例。

相关问题