I’m a newbie, trying to take a freeware application last updated in 2008 and since (apparently) abandoned by the programmers, who haven’t responded to my emails, and both update it for the current MacOS and also create a version for the iPhone. I imagine this is going to be a long and somewhat nightmarish process but I’m looking forward to learning.
Right now I’m at the beginning stages, and I’m looking at the following GeniusPair.h file in the original:
#import <Foundation/Foundation.h>
@class GeniusItem;
@class GeniusAssociation;
extern const int kGeniusPairDisabledImportance;
extern const int kGeniusPairMinimumImportance;
extern const int kGeniusPairNormalImportance;
extern const int kGeniusPairMaximumImportance;
@interface GeniusPair : NSObject <NSCoding, NSCopying> {
GeniusAssociation * _associationAB; //!< Stats for standard learning mode directional relationship.
GeniusAssociation * _associationBA; //!< Stats for Jepardy style learning mode directional relationship.
NSMutableDictionary * _userDict;
}
+ (NSArray *) associationsForPairs:(NSArray *)pairs useAB:(BOOL)useAB useBA:(BOOL)useBA;
- (id) initWithItemA:(GeniusItem *)itemA itemB:(GeniusItem *)itemB userDict:(NSMutableDictionary *)userDict;
//various other methods declared
@end
@interface GeniusPair (GeniusDocumentAdditions)
- (BOOL) disabled;
//various other methods declared
@end
@interface GeniusPair (TextImportExport)
- (NSString *) tabularTextByOrder:(NSArray *)keyPaths;
//various other methods declared
@end
My question is (questions are): Why have more than one interface in a .h file? What’s the difference between @interface GeniusPair : NSObject and @interface GeniusPair (TextImportExport)? What does having an @interface followed by something in parentheses do vs. an @interface followed by a colon?
Thanks so much in advance for your help explaining.
It’s called a category. Categories are useful for extending classes (when you don’t have their source code, like UIKit or Foundation classes) or separating extended/advanced functionality of a class from its base methods (this is the case you encountered).
They can also be used for emulating private methods when used within an implementation (as opposed to declaration) context in an
.mfile.More on the topic at Apple Developer..