I'm having a lot of difficulty with CoreData. The learning curve is very steep. I'm a pretty novice XCode user and don't know much about databases either. I've spent quite a while trying to figure out what approach to take for my program and have just been stumbling along really.
I tried to learn sqlite because that's what I thought coreData used. So, I made a huge database with many relationships in LibreOffice because it was a free Database program. Then, I realized it was in HSQL, which is different than SQLite. So then I had to export everything into .csv's and lost my relationships, then paid for a crappy program called SQLiteManager to create SQLite database tables.
Once I had everything setup, I started looking at CoreData again and I realized that CoreData doesn't allow you to use an external sqlite database! Aghh. At this point, I am pretty frustrated. So, now, I've started from scratch again with coreData and built my empty model with entities, attributes, relationships, etc. all in the managed Object form. I have checked that it is able to create the empty 'proprietary' coreData SQLite database when building, and that works.
But now, I'm trying to fill in the managedObjects, but am having trouble with the relationships
This is what one of my header files looks like.
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
@class ORGAN, SPECIMEN, SYSTEM, TISSUE;
@interface CELL : NSManagedObject
@property (nonatomic, retain) NSString * cellDescription;
@property (nonatomic, retain) NSString * cellName;
@property (nonatomic, retain) NSString * cellSID;
@property (nonatomic, retain) NSSet *organs;
@property (nonatomic, retain) NSSet *specimens;
@property (nonatomic, retain) NSSet *systems;
@property (nonatomic, retain) NSSet *tissues;
@end
@interface CELL (CoreDataGeneratedAccessors)
- (void)addOrgansObject:(ORGAN *)value;
- (void)removeOrgansObject:(ORGAN *)value;
- (void)addOrgans:(NSSet *)values;
- (void)removeOrgans:(NSSet *)values;
- (void)addSpecimensObject:(SPECIMEN *)value;
- (void)removeSpecimensObject:(SPECIMEN *)value;
- (void)addSpecimens:(NSSet *)values;
- (void)removeSpecimens:(NSSet *)values;
- (void)addSystemsObject:(SYSTEM *)value;
- (void)removeSystemsObject:(SYSTEM *)value;
- (void)addSystems:(NSSet *)values;
- (void)removeSystems:(NSSet *)values;
- (void)addTissuesObject:(TISSUE *)value;
- (void)removeTissuesObject:(TISSUE *)value;
- (void)addTissues:(NSSet *)values;
- (void)removeTissues:(NSSet *)values;
@end
and, in my applicationDelegate file, I am trying to populate my coreData Database using customs "@" delimited files in the resource sections (although, I presume I could run SQLite connections to my old DB and do the same, but that is another issue)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//cells
NSString *paths = [[NSBundle mainBundle] resourcePath];
NSString *bundlePath = [paths stringByAppendingPathComponent:@"cells"];
NSString *dataFile = [[NSString alloc] initWithContentsOfFile:bundlePath];
NSArray *dataRows = [dataFile componentsSeparatedByString:@"\n"];
for (int i = 0 ; i < [dataRows count] ; i++)
{
NSArray *dataElements = [[dataRows objectAtIndex:i] componentsSeparatedByString:@"@"];
if ([dataElements count] >= 2)
{
CELL *cellMO = [NSEntityDescription insertNewObjectForEntityForName:@"CELL"
inManagedObjectContext:[self managedObjectContext]];
cellMO.cellName = [dataElements objectAtIndex:0];
cellMO.cellDescription = [dataElements objectAtIndex:1];
cellMO.organs ???????????????????????????? can't make this work.
}
}
It keeps breaking when I build with this line and I've tried with several different approaches. It keeps saying that cellMO.organs is expecting an NSSet, but it fails when I try to give it an NSSet. So, I'm lost. Please Help?????????