I know that @class is suppose to speed up compile time, but if I had a case like this:
#import <Foundation/Foundation.h>
@class BNRItem;
@interface BNRItemStore : NSObject
@end
#import "BNRItemStore.h"
#import "BNRItem.h"
@implementation BNRItemStore
@end
Could I do this instead and still get the same compile time:
#import <Foundation/Foundation.h>
#import "BNRItem.h"
@interface BNRItemStore : NSObject
@end
#import "BNRItemStore.h"
@implementation BNRItemStore
@end
(assuming you actually use
BNRItemsomeplace in these files)it would be the same for
BNRItemStore.m, but it is likely to increase compile times and recompilation frequency for anything that#importsBNRItemStore.h— because it’s common that many classes that need to seeBNRItemStoredo not need to also seeBNRItem‘s@interface.as that pattern spreads to many headers in your projects, a simple edit to one header can require recompiling a large set of files, with a large set of included files. it also spreads to the indexer, which is continually indexing based on changes.
best to use the forward declarations, unless your project is (and will remain) tiny.
it’s actually really nice to be able to declare all your instance variables/properties in the
.m— as this is a fairly new addition to clang. abstraction and build times can improve significantly.