What is the point of re-declaring a class interface in an implementation file?

In some Apple Iphone examples, some properties are declared in the header file and some properties in the implementation file. For example, in Siesmic XML examples

ParseOperation.h

@interface ParseOperation : NSOperation {
NSData *earthquakeData;

@private
NSDateFormatter *dateFormatter;

// these variables are used during parsing
Earthquake *currentEarthquakeObject;
Contact *currentContactObject;
NSMutableArray *currentParseBatch;
NSMutableString *currentParsedCharacterData;

BOOL accumulatingParsedCharacterData;
BOOL didAbortParsing;
NSUInteger parsedEarthquakesCounter;
}

@property (copy, readonly) NSData *earthquakeData;

@end

ParseOperation.m

@interface ParseOperation () <NSXMLParserDelegate>
  @property (nonatomic, retain) Earthquake *currentEarthquakeObject;
  @property (nonatomic, retain) NSMutableArray *currentParseBatch;
  @property (nonatomic, retain) NSMutableString *currentParsedCharacterData;
  @property (nonatomic, retain) Contact *currentContactObject;
@end

What is the use of an additional interface declaration in the implementation file?

+3
source share
1 answer

. , , . , , .

// Foo.h – the public interface
@interface Foo : NSObject {…}

// Collaborators can only read bar.
@property(readonly) int bar;
@property(readonly) int baz;

@end

// Foo.m
#import "Foo.h"

// Private interface
@interface Foo ()

// Inside class implementation we can also change bar.
@property(assign) int bar;
@property(assign) int other;

@end

@implementation Foo
@synthesize bar, baz, other;
@end
+5

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


All Articles