|
4 | 4 | @implementation NSEntityDescription (CDEAdditions)
|
5 | 5 |
|
6 | 6 | #pragma mark - Convenience
|
7 |
| -- (NSArray *)supportedAttributes_cde { |
8 |
| - NSMutableArray *result = [NSMutableArray new]; |
9 |
| - for(NSAttributeDescription *attribute in [[self attributesByName] allValues]) { |
10 |
| - // Ignore transient properties |
11 |
| - if(attribute.isTransient) { |
12 |
| - continue; |
13 |
| - } |
14 |
| - if(!attribute.isSupportedAttribute_cde) { |
15 |
| - continue; |
16 |
| - } |
17 |
| - |
18 |
| - [result addObject:attribute]; |
| 7 | +- (NSArray<NSAttributeDescription*> *)supportedAttributes_cde { |
| 8 | + NSMutableArray *result = [NSMutableArray new]; |
| 9 | + for(NSAttributeDescription *attribute in [[self attributesByName] allValues]) { |
| 10 | + // Ignore transient properties |
| 11 | + if(attribute.isTransient) { |
| 12 | + continue; |
19 | 13 | }
|
20 |
| - return result; |
| 14 | + if(!attribute.isSupportedAttribute_cde) { |
| 15 | + continue; |
| 16 | + } |
| 17 | + |
| 18 | + [result addObject:attribute]; |
| 19 | + } |
| 20 | + return result; |
21 | 21 | }
|
22 | 22 |
|
23 |
| -- (NSArray *)toManyRelationships_cde { |
24 |
| - NSMutableArray *result = [NSMutableArray new]; |
25 |
| - [self.relationshipsByName enumerateKeysAndObjectsUsingBlock:^(id key, NSRelationshipDescription *relation, BOOL *stop) { |
26 |
| - if(relation.isToMany == NO) { |
27 |
| - return; |
28 |
| - } |
29 |
| - [result addObject:relation]; |
30 |
| - }]; |
31 |
| - return result; |
| 23 | +- (NSArray<NSRelationshipDescription*> *)toManyRelationships_cde { |
| 24 | + NSMutableArray *result = [NSMutableArray new]; |
| 25 | + [self.relationshipsByName enumerateKeysAndObjectsUsingBlock:^(id key, NSRelationshipDescription *relation, BOOL *stop) { |
| 26 | + if(relation.isToMany == NO) { |
| 27 | + return; |
| 28 | + } |
| 29 | + [result addObject:relation]; |
| 30 | + }]; |
| 31 | + return result; |
32 | 32 | }
|
33 | 33 |
|
34 |
| -- (NSDictionary *)toManyRelationshipsByName_cde { |
35 |
| - NSMutableDictionary *result = [NSMutableDictionary new]; |
36 |
| - [self.relationshipsByName enumerateKeysAndObjectsUsingBlock:^(NSString *name, NSRelationshipDescription *relation, BOOL *stop) { |
37 |
| - if(relation.isToMany == NO) { |
38 |
| - return; |
39 |
| - } |
40 |
| - result[name] = relation; |
41 |
| - }]; |
42 |
| - return result; |
| 34 | +- (NSDictionary<NSString*, NSRelationshopDescription*> *)toManyRelationshipsByName_cde { |
| 35 | + NSMutableDictionary *result = [NSMutableDictionary new]; |
| 36 | + [self.relationshipsByName enumerateKeysAndObjectsUsingBlock:^(NSString *name, NSRelationshipDescription *relation, BOOL *stop) { |
| 37 | + if(relation.isToMany == NO) { |
| 38 | + return; |
| 39 | + } |
| 40 | + result[name] = relation; |
| 41 | + }]; |
| 42 | + return result; |
43 | 43 | }
|
44 | 44 |
|
45 |
| -- (NSArray *)sortedToManyRelationshipNames_cde { |
46 |
| - NSArray *unsorted = [[self toManyRelationshipsByName_cde] allKeys]; |
47 |
| - return [unsorted sortedArrayWithOptions:NSSortStable usingComparator:^NSComparisonResult(NSString *relationA, NSString *relationB) { |
48 |
| - return [relationA localizedStandardCompare:relationB]; |
49 |
| - }]; |
| 45 | +- (NSArray<NSString*> *)sortedToManyRelationshipNames_cde { |
| 46 | + NSArray *unsorted = [[self toManyRelationshipsByName_cde] allKeys]; |
| 47 | + return [unsorted sortedArrayWithOptions:NSSortStable usingComparator:^NSComparisonResult(NSString *relationA, NSString *relationB) { |
| 48 | + return [relationA localizedStandardCompare:relationB]; |
| 49 | + }]; |
50 | 50 | }
|
51 | 51 |
|
52 |
| -- (NSArray *)sortedToManyRelationships_cde { |
53 |
| - NSMutableArray *result = [NSMutableArray new]; |
54 |
| - [self.relationshipsByName enumerateKeysAndObjectsUsingBlock:^(id key, NSRelationshipDescription *relation, BOOL *stop) { |
55 |
| - if(relation.isToMany == NO) { |
56 |
| - return; |
57 |
| - } |
58 |
| - [result addObject:relation]; |
59 |
| - }]; |
60 |
| - return [result sortedArrayWithOptions:NSSortStable usingComparator:^NSComparisonResult(NSRelationshipDescription *relationA, NSRelationshipDescription *relationB) { |
61 |
| - return [relationA.name localizedStandardCompare:relationB.name]; |
62 |
| - }]; |
| 52 | +- (NSArray<NSRelationshipDescription*> *)sortedToManyRelationships_cde { |
| 53 | + NSMutableArray *result = [NSMutableArray new]; |
| 54 | + [self.relationshipsByName enumerateKeysAndObjectsUsingBlock:^(id key, NSRelationshipDescription *relation, BOOL *stop) { |
| 55 | + if(relation.isToMany == NO) { |
| 56 | + return; |
| 57 | + } |
| 58 | + [result addObject:relation]; |
| 59 | + }]; |
| 60 | + return [result sortedArrayWithOptions:NSSortStable usingComparator:^NSComparisonResult(NSRelationshipDescription *relationA, NSRelationshipDescription *relationB) { |
| 61 | + return [relationA.name localizedStandardCompare:relationB.name]; |
| 62 | + }]; |
63 | 63 | }
|
64 | 64 |
|
65 |
| -- (NSArray *)sortedToOneRelationships_cde { |
66 |
| - NSMutableArray *result = [NSMutableArray new]; |
67 |
| - [self.relationshipsByName enumerateKeysAndObjectsUsingBlock:^(id key, NSRelationshipDescription *relation, BOOL *stop) { |
68 |
| - if(relation.isToMany) { |
69 |
| - return; |
70 |
| - } |
71 |
| - [result addObject:relation]; |
72 |
| - }]; |
73 |
| - return [result sortedArrayWithOptions:NSSortStable usingComparator:^NSComparisonResult(NSRelationshipDescription *relationA, NSRelationshipDescription *relationB) { |
74 |
| - return [relationA.name localizedStandardCompare:relationB.name]; |
75 |
| - }]; |
| 65 | +- (NSArray<NSRelationshipDescription*> *)sortedToOneRelationships_cde { |
| 66 | + NSMutableArray *result = [NSMutableArray new]; |
| 67 | + [self.relationshipsByName enumerateKeysAndObjectsUsingBlock:^(id key, NSRelationshipDescription *relation, BOOL *stop) { |
| 68 | + if(relation.isToMany) { |
| 69 | + return; |
| 70 | + } |
| 71 | + [result addObject:relation]; |
| 72 | + }]; |
| 73 | + return [result sortedArrayWithOptions:NSSortStable usingComparator:^NSComparisonResult(NSRelationshipDescription *relationA, NSRelationshipDescription *relationB) { |
| 74 | + return [relationA.name localizedStandardCompare:relationB.name]; |
| 75 | + }]; |
76 | 76 | }
|
77 | 77 |
|
78 |
| -- (NSArray *)sortedRelationships_cde { |
79 |
| - return [self.relationshipsByName.allValues sortedArrayWithOptions:NSSortStable usingComparator:^NSComparisonResult(NSRelationshipDescription *relationA, NSRelationshipDescription *relationB) { |
80 |
| - return [relationA.name localizedStandardCompare:relationB.name]; |
81 |
| - }]; |
| 78 | +- (NSArray<NSRelationshipDescription*> *)sortedRelationships_cde { |
| 79 | + return [self.relationshipsByName.allValues sortedArrayWithOptions:NSSortStable usingComparator:^NSComparisonResult(NSRelationshipDescription *relationA, NSRelationshipDescription *relationB) { |
| 80 | + return [relationA.name localizedStandardCompare:relationB.name]; |
| 81 | + }]; |
82 | 82 | }
|
83 | 83 |
|
84 |
| -//- (NSString *)nameForDisplay_cde { |
85 |
| -// return [self.name humanReadableStringAccordingToUserDefaults_cde]; |
86 |
| -//} |
87 |
| - |
88 | 84 | - (NSAttributeDescription *)attributeDescriptionForName_cde:(NSString *)attributeName {
|
89 |
| - NSParameterAssert(attributeName); |
90 |
| - return self.attributesByName[attributeName]; |
| 85 | + NSParameterAssert(attributeName); |
| 86 | + return self.attributesByName[attributeName]; |
91 | 87 | }
|
92 | 88 |
|
93 |
| -//#pragma mark - CSV |
94 |
| -//// returns an array of arrays |
95 |
| -//- (NSArray *)CSVValuesForEachManagedObjectInArray_cde:(NSArray *)objects { |
96 |
| -// NSParameterAssert(objects); |
97 |
| -// NSArray *supportedAttributes = self.supportedCSVAttributes_cde; |
98 |
| -// NSArray *supportedAttributeNames = [supportedAttributes valueForKey:@"name"]; |
99 |
| -// return [self CSVValuesForEachManagedObjectInArray:objects forPropertyNames:supportedAttributeNames includeHeaderValues_cde:NO]; |
100 |
| -//} |
101 |
| -// |
102 |
| -//// This method filters out any non supported property names and also respects the sorting of propertyNames |
103 |
| -//- (NSArray *)CSVValuesForEachManagedObjectInArray:(NSArray *)objects forPropertyNames:(NSArray *)propertyNames includeHeaderValues_cde:(BOOL)includeHeaderValues { |
104 |
| -// NSParameterAssert(objects); |
105 |
| -// NSParameterAssert(propertyNames); |
106 |
| -// |
107 |
| -// NSMutableArray *supportedAttributeNames = [NSMutableArray new]; |
108 |
| -// for(NSString *propertyName in propertyNames) { |
109 |
| -// if([propertyName isEqualToString:@"objectID"]) { |
110 |
| -// [supportedAttributeNames addObject:propertyName]; |
111 |
| -// continue; |
112 |
| -// } |
113 |
| -// NSAttributeDescription *attribute = self.attributesByName[propertyName]; |
114 |
| -// if(attribute == nil) { |
115 |
| -// continue; |
116 |
| -// } |
117 |
| -// if(!attribute.isSupportedAttribute_cde || !attribute.isSupportedCSVAttribute_cde) { |
118 |
| -// continue; |
119 |
| -// } |
120 |
| -// [supportedAttributeNames addObject:attribute.name]; |
121 |
| -// } |
122 |
| -// |
123 |
| -// NSMutableArray *result = [NSMutableArray arrayWithCapacity:objects.count + 1]; |
124 |
| -// |
125 |
| -// if(includeHeaderValues) { |
126 |
| -// [result addObject:supportedAttributeNames]; |
127 |
| -// } |
128 |
| -// |
129 |
| -// for(NSManagedObject *object in objects) { |
130 |
| -// NSAssert([object.entity isKindOfEntity:self], @"Entity mismatch"); |
131 |
| -// NSArray *values = [object CSVValuesForAttributeNames_cde:supportedAttributeNames]; |
132 |
| -// [result addObject:values]; |
133 |
| -// } |
134 |
| -// |
135 |
| -// return result; |
136 |
| -//} |
137 |
| -// |
138 |
| -//- (NSArray *)supportedCSVAttributes_cde { |
139 |
| -// NSMutableArray *result = [NSMutableArray new]; |
140 |
| -// for(NSAttributeDescription *attribute in self.supportedAttributes_cde) { |
141 |
| -// if(attribute.isSupportedCSVAttribute_cde) { |
142 |
| -// [result addObject:attribute]; |
143 |
| -// } |
144 |
| -// } |
145 |
| -// return result; |
146 |
| -//} |
147 |
| - |
148 | 89 | #pragma mark - UI
|
149 | 90 | - (UIImage *)icon_cde {
|
150 | 91 | return nil;
|
151 |
| -// return [UIImage imageNamed:@"entity-icon-small"]; |
152 | 92 | }
|
153 | 93 |
|
154 | 94 | @end
|
0 commit comments