Adding data from text inputs to Entity in Xcode
I am a new developer and am working on my first app in Xcode. In trying to
add data to an Entity named "Rounds." I am getting the error message:
* Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '+entityForName: nil is not a legal NSManagedObjectContext
parameter searching for entity name 'Rounds'
In debugging the app is crashing at the line:
Rounds *rounds= (Rounds*)[NSEntityDescription
insertNewObjectForEntityForName:@"Rounds" inManagedObjectContext:
self.managedObjectContext];
From my limited knowledge I feel like this is happening because
managedObjectContext is not instantiated. How do I fix this? Thanks in
advance.
-(void)AddRound
NSNumber *rating = [[NSNumber alloc] initWithDouble:[ratingValue.text
integerValue]];
NSNumber *slope = [[NSNumber alloc] initWithDouble:[slopeValue.text
integerValue]];
NSNumber *score= [[NSNumber alloc] initWithDouble:[scoreValue.text
integerValue]];
NSString *courseName = courseNameValue.text;
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MM-dd-yyyy"];
NSDate *date = [formatter dateFromString:dateValue.text];
Rounds *rounds= (Rounds*)[NSEntityDescription
insertNewObjectForEntityForName:@"Rounds" inManagedObjectContext:
self.managedObjectContext];
[rounds setRoundRating:rating];
[rounds setRoundSlope:slope];
[rounds setRoundScore:score];
[rounds setRoundDate:date];
[rounds setRoundCourseName:courseName];
NSError * error;
[self.managedObjectContext save:&error];
No comments:
Post a Comment