开发者

Why Am I Getting This NSManaged Object Error

开发者 https://www.devze.com 2023-02-28 23:49 出处:网络
Getting error at line [theSelectedRoutine addExerciseObject: exercise]; saying method -addExerciseObject not found.

Getting error at line [theSelectedRoutine addExerciseObject: exercise]; saying method -addExerciseObject not found.

Interface: @property (nonatomic, retain) Routine *theSelectedRoutine;

-(void)addExercise
{   
    if (managedObjectContext == nil) 
    { 
        managedObjectContext = [(CurlAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext]; 
        [managedObjectContext retain];
    }

    UIBarButtonItem *addButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(exerciseChooser)];
    self.navigationItem.rightBarButtonItem = addButton;
    [addButton release];

    NSError *error = nil;

    Exercise *exercise = (Exercise *)[NSEntityDescription insertNewObjectForEntityForName:@"Exercise" inManagedObjectContext:managedObjectContext];

    exercise.name = selectedExercise;

    [theSelectedRoutine addExerciseObject: exercise];

    if (![managedObjectContext save:&error]) 
    {
  开发者_StackOverflow社区      // Handle the error.
    }
    NSLog(@"%@", error);

    [self.routineTableView reloadData];

}

..

Routine Class
#import "Routine.h"
#import "Exercise.h"


@implementation Routine
@dynamic name;
@dynamic timeStamp;
@dynamic routineExercises;

- (void)addRoutineExercisesObject:(Exercise *)value {    
    NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1];
    [self willChangeValueForKey:@"routineExercises" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];
    [[self primitiveValueForKey:@"routineExercises"] addObject:value];
    [self didChangeValueForKey:@"routineExercises" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];
    [changedObjects release];
}

- (void)removeRoutineExercisesObject:(Exercise *)value {
    NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1];
    [self willChangeValueForKey:@"routineExercises" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects];
    [[self primitiveValueForKey:@"routineExercises"] removeObject:value];
    [self didChangeValueForKey:@"routineExercises" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects];
    [changedObjects release];
}

- (void)addRoutineExercises:(NSSet *)value {    
    [self willChangeValueForKey:@"routineExercises" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value];
    [[self primitiveValueForKey:@"routineExercises"] unionSet:value];
    [self didChangeValueForKey:@"routineExercises" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value];
}

- (void)removeRoutineExercises:(NSSet *)value {
    [self willChangeValueForKey:@"routineExercises" withSetMutation:NSKeyValueMinusSetMutation usingObjects:value];
    [[self primitiveValueForKey:@"routineExercises"] minusSet:value];
    [self didChangeValueForKey:@"routineExercises" withSetMutation:NSKeyValueMinusSetMutation usingObjects:value];
}


@end


Well I don't see addExerciseObject either, shouldn't it be [theSelectedRoutine addRoutineExercisesObject:exercise]; ?

0

精彩评论

暂无评论...
验证码 换一张
取 消