when creating a library that will be used in several projects, I encountered an error that I could not solve on my own.
The library consists of several "modules", each of which declares a set of its classes. Modules declare a header file that references classes. Each module header is included in the library header, and all of them are copied to the target library.
The module "GMData" defines the library ORM layer, it declares the class "GMInitializerBase", its purpose is to initialize the module. It must be called once in a UIApplicationDelegate.
The GMModel module contains the basic model for the application (categories, articles, ...), it must register with GMData for proper operation.
Structure:
<Library Root>
Library.h
<GMData>
GMData.h
GMInitializerBase.{h,m}
<GMModel>
GMModel.h
GMInitializerBase+GMModel.{h,m}
Library Content .h
#import "GMData.h"
#import "GMModel.h"
GMData.h file content
#import "... ORM related headers ..."
#import "GMInitializerBase.h"
The contents of the GMInitializerBase database. {h, m}
#import "... ORM Classes ..."
@interface GMInitializerBase : NSObject {
}
+ (void) bootstrap;
+ (GMInitializerBase*) initializer;
- (void) setup;
- (void) setupStore:(GMManagerFactory*)factory;
- (void) setupHelpers:(GMHelperFactory*)factory;
- (void) setupManagers:(GMManagerFactory*)factory;
@end
@implementation GMInitializerBase
+ (void) bootstrap {
GMInitializerBase* initializer = [self initializer];
[initializer setup];
}
- (void) setup {
GMHelperFactory* helperFactory = [GMHelperFactory sharedInstance];
GMManagerFactory* managerFactory = [GMManagerFactory sharedInstance];
[self setupStore:managerFactory];
[self setupHelpers:helperFactory];
[self setupManagers:managerFactory];
}
@end
GMModel.h content
#import "... Base Models files ..."
#import "GMInitializerBase+GMModel.h"
The contents of GMInitializerBase + GMModel. {h, m}
@interface GMInitializerBase (GMModel_Additions)
- (void) setup;
- (void) setupGMModelHelpers:(GMHelperFactory*)factory;
- (void) setupGMModelManagers:(GMManagerFactory*)factory;
@end
@implementation GMInitializerBase (GMModel_Additions)
- (void) setup {
GMHelperFactory* helperFactory = [GMHelperFactory sharedInstance];
GMManagerFactory* managerFactory = [GMManagerFactory sharedInstance];
[self setupStore:managerFactory];
[self setupGMModelHelpers:helperFactory];
[self setupGMModelManagers:managerFactory];
[self setupHelpers:helperFactory];
[self setupManagers:managerFactory];
}
- (void) setupGMModelHelpers:(GMHelperFactory*)factory { }
- (void) setupGMModelManagers:(GMManagerFactory*)factory { }
@end
The contents of ProjectAppDelegate.m (located in another project, includes the .a library and a search in the Titles directory)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[GMInitializerBase initializer] setup];
}
Stop at the first breakpoint (breakpoint 01) It crashed when in the library:
- I declare adding without overloading the method;
- I declare an addition to the Cocoa class ([NSString toto]) without overloading;
In work, when in a test project:
- I declare an addition to the Cocoa class ([NSString toto]) without overloading;
I did not try to overload the library class, but I assume that it will work too.
: , .
, .