Question

As projects start to grow I tend to split up the code logically into several .h/.m files. I like to do this especially when the model part (of MVC pattern applications) is the big part.

A logical example would be to split up the data loading/saving part and the data editing part (e.g. all the calculation methods). But now I face some circular linking problems:

// DATA SAVING/LOADING PART

#import "DataSavingLoading.h"
#import "DataCalculation.h"

@implementation DataSavingLoading

+ (NSDictionary *)loadData 
{
     // loading goes here ...
     if (!data) {
         NSDictionary *newData = [self createData];
         [self saveData:newData];
         return newData;
}

+ (void)saveData:(NSDictionary *)data { ... }

+ (NSDictionary *)createData
{
     NSDictionary *newData = @{...};
     return [DataCalculation calculateInitialData:newData];
}

+ (NSDictionary *)loadDataConfiguration { ... }

@end

and then in the calculation part:

// DATA CALCULATION PART

#import "DataCalculation.h"
#import "DataSavingLoading.h"

@implementation DataCalculation

+ (NSDictionary *)calculateInitialData:(NSDictionary *)initalData 
{
     // Get config
     NSDictionary *dataConfig = [DataSavingLoading loadDataConfiguration];

     // Calculation goes here...

     return calculatedDataConfig;
}

@end

The Data Loading part includes the Data calculation part because the calculation method is called. The Data Calculation part has to include the Data Loading part as it needs some config stuff. Can I get any problems with that circular linking? Or is there any better concept to organize a big bunch of methods in the model part?

Était-ce utile?

La solution

#import is not #include, you shouldn't be having problems with that.

What is the difference between #import and #include in Objective-C?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top