forked from Xcode-Snippets/Objective-C
-
Notifications
You must be signed in to change notification settings - Fork 0
/
core_data_to-many_relationship_accessors.m
39 lines (36 loc) · 2.18 KB
/
core_data_to-many_relationship_accessors.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Core Data To-Many Relationship Accessors
// Used for overriding the add and remove methods for a to-many relationship.
//
// IDECodeSnippetCompletionPrefix:
// IDECodeSnippetCompletionScopes: [ClassImplementation]
// IDECodeSnippetIdentifier: C1E91503-E91F-4EEA-A032-D98D80CDD00A
// IDECodeSnippetLanguage: Xcode.SourceCodeLanguage.Objective-C
// IDECodeSnippetVersion: 1
- (void)add<#Capitalized relationship name#>Object:(<#Relationship destination class#> *)value
{
NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1];
[self willChangeValueForKey:@"<#Relationship name#>" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];
[[self primitiveValueForKey:@"<#Relationship name#>"] addObject:value];
[self didChangeValueForKey:@"<#Relationship name#>" withSetMutation:NSKeyValueUnionSetMutation usingObjects:changedObjects];
[changedObjects release];
}
- (void)remove<#Capitalized relationship name#>Object:(<#Relationship destination class#> *)value
{
NSSet *changedObjects = [[NSSet alloc] initWithObjects:&value count:1];
[self willChangeValueForKey:@"<#Relationship name#>" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects];
[[self primitiveValueForKey:@"<#Relationship name#>"] removeObject:value];
[self didChangeValueForKey:@"<#Relationship name#>" withSetMutation:NSKeyValueMinusSetMutation usingObjects:changedObjects];
[changedObjects release];
}
- (void)add<#Capitalized relationship name#>:(NSSet *)value
{
[self willChangeValueForKey:@"<#Relationship name#>" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value];
[[self primitiveValueForKey:@"<#Relationship name#>"] unionSet:value];
[self didChangeValueForKey:@"<#Relationship name#>" withSetMutation:NSKeyValueUnionSetMutation usingObjects:value];
}
- (void)remove<#Capitalized relationship name#>:(NSSet *)value
{
[self willChangeValueForKey:@"<#Relationship name#>" withSetMutation:NSKeyValueMinusSetMutation usingObjects:value];
[[self primitiveValueForKey:@"<#Relationship name#>"] minusSet:value];
[self didChangeValueForKey:@"<#Relationship name#>" withSetMutation:NSKeyValueMinusSetMutation usingObjects:value];
}