Core Data Accessors

 

Accessorizer 3 introduces two new actions to the Action Menu and Action Panel for Core Data.

Core Data

Core Data Accessors

Accessorizer’s Core Data action will smartly handle an object vs scalar when creating the accessors.

With these ivars or properties,


NSString *name;

CGFloat radius;


the results are:

- (NSString *)name {

    [self willAccessValueForKey:@"name"];

    NSString *tmpValue = [self primitiveValueForKey:@"name"];

    [self didAccessValueForKey:@"name"];

    return tmpValue;

}

- (void)setName:(NSString *)value {

    [self willChangeValueForKey:@"name"];

    [self setPrimitiveValue:value forKey:@"name"];

    [self didChangeValueForKey:@"name"];

}

- (CGFloat)radius {

    [self willAccessValueForKey:@"radius"];

    CGFloat tmpValue = radius;

    [self didAccessValueForKey:@"radius"];

    return tmpValue;

}

- (void)setRadius:(CGFloat)value {

    [self willChangeValueForKey:@"radius"];

    radius = value;

    [self didChangeValueForKey:@"radius"];

}


When generating code for a To-Many relationship, a utility panel will pop open where you can define your collection name and your class of objects.

Core Data To-Many Relationship

- (void)addEmployeesObject:(Employee *) value {

    NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1];

    [self willChangeValueForKey:@"employees" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];

    [[self primitiveValueForKey:@"employees"] addObject:value];

    [self didChangeValueForKey:@"employees" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];

    [changedObjects release];

}

- (void)removeEmployeesObject:(Employee *) value {

    NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1];

    [self willChangeValueForKey:@"employees" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects];

    [[self primitiveValueForKey:@"employees"] removeObject:value];

    [self didChangeValueForKey:@"employees" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects];

    [changedObjects release];

}

- (void)addEmployeesObject:(NSSet *)value {

    [self willChangeValueForKey:@"employees" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value];

    [[self primitiveValueForKey:@"employees"] unionSet:value];

    [self didChangeValueForKey:@"employees" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value];

}

- (void)removeEmployeesObject:(NSSet *)value {

    [self willChangeValueForKey:@"employees" withSetMutation:NSKeyValueMinusSetMutation usingObjects:value];

    [[self primitiveValueForKey:@"employees"] minusSet:value];

    [self didChangeValueForKey:@"employees" withSetMutation:NSKeyValueMinusSetMutation usingObjects:value];

}

NOTE: if you leave the text fields blank, Accessorizer will insert place-holders.