I am building backend and frontend code for my iOS application. The frontend code will be build for iPhone and then iPad later. But the backend code is going to be the same. My few developers are working on backend and some on frontend. Backend, application uses CoreData. I was thinking to create backend code as static library and have it linked in frontend code. But that seems to be too complicated. Is there any other mechanism for example, Backend project say P1 is build as Empty application and frontend is build as P2. And somehow make sure P1 cannot use any of the classes/files/code from P2 (means P1 does not depend on P2) but P2 can use classes/API etc from P1. I want to enforce that P1 does not (inadvertently) uses any of P2 code to have the dependency separation clean. Any suggestions?
Asked
Active
Viewed 138 times
1 Answers
2
I think a static library is a good solution. Like you can create a helper class for fetching data from the core-data database. For example:
+ (NSArray *)fetchAllUsers;
+ (User *)fetchUserByName:(NSString *)name;
the front-end developers only know that you can call these methods. The back-end developers are responsible for the working of the method.
If you need an instantiation, consider a singelton class.
Edit: (Example for static core-data class)
+ (void)insertNewUserWithName:(NSString *)name
{
NSManagedObjectContext *context = [self managedObjectContext];
User *user = [NSEntityDescription insertNewObjectForEntityForName:@"Users"
inManagedObjectContext:context];
[user setName:name];
NSError *error;
if (![context save:&error])
{
NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);
}
}
-
Thanks Juzzz. Do you have any handy mechanism to create static library as following: a) Create static lib myLib.a that has CoreData stuff in it and exposes some APIs to be used by others. b) Create iPhone application MyApp project without CoreData stuff and it simply calls an API exposed using myLib.a say createUser, deleteUser etc. In other words, MyApp does not even know that myLib.a is using CoreData to imlement this createUser API. ANy thoughts? – theiOSguy Apr 14 '12 at 20:01
-
The problem with your concept is that the iOS application has to be core-data enabled with a Database like SQLite. When your database is the same conform as other apps you made, you can create a static library to do fetch/edit/etc on your data. But when creating the static library ones, with pretty dynamic, reusable methods its easy to alter. I will create a simple example in my post for you. – Justin Apr 14 '12 at 20:16