I recommend setting up your database model in xcode, and then when you do this, select the objects and select File> New File from the menu. Then select the Managed Feature Class from the Cocoa touch class. After "Next", select where to save the files, and in the next step Xcode will ask you which objects should be generated for the files.
After you have done this, you can implement the functions that you need, for example, you delegate. My recommendation is to leave your existing things as they are and use the main data classes as their own. Just pull the data you want from existing classes / arrays and put them into the database as needed. When extracting, on the contrary ... get them from the database and add them to your functions / classes.
An example from one of my projects:
.H file
@class quicklistSet; @interface rankedAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> { [...] NSMutableArray *_searchHistory; NSMutableArray *_quickList; } [...] @property (nonatomic, retain) NSMutableArray *_searchHistory; @property (nonatomic, retain) NSMutableArray *_quickList; - (void)addToQuicklist:(quicklistSet *)theQuicklistSet; - (BOOL)checkIfQuicklistExists:(quicklistSet*)theQuicklistSet; - (NSMutableArray *)getQuicklists; - (void)deleteQuicklist:(NSNumber*)theAppId; @end
.M file
#import "quicklistSet.h" #import "quicklist.h" @implementation rankedAppDelegate @synthesize window; @synthesize tabBarController; @synthesize _searchHistory, _quickList; [...] - (void)addToQuicklist:(quicklistSet *)theQuicklistSet { BOOL exists = [self checkIfQuicklistExists:theQuicklistSet]; if(!exists) { quicklist *theQuicklist = (quicklist *)[NSEntityDescription insertNewObjectForEntityForName:@"quicklist" inManagedObjectContext:self.managedObjectContext]; [theQuicklist setAppName:[theQuicklistSet _appName]]; [theQuicklist setAppId:[theQuicklistSet _appId]]; [theQuicklist setAppImage:[theQuicklistSet _appImage]]; [theQuicklist setCountryId:[theQuicklistSet _countryId]]; [theQuicklist setCategoryId:[theQuicklistSet _categoryId]]; [theQuicklist setLastCheck:[theQuicklistSet _lastCheck]]; [theQuicklist setLastRank:[theQuicklistSet _lastRank]]; [_quickList addObject:theQuicklist]; [self saveAction]; } else { NSLog(@"Existing quicklistSet: %@", [theQuicklistSet _appName]); } } - (BOOL)checkIfQuicklistExists:(quicklistSet*)theQuicklistSet {
EDIT: QuicklistSet was my existing class, quicklist is my coredata class.
source share