This repository was archived by the owner on Jul 1, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +65
-0
lines changed
Expand file tree Collapse file tree 3 files changed +65
-0
lines changed Original file line number Diff line number Diff line change 4444- (void )dataObject : (VSDataObject *)dataObject willChangeValueForKey : (NSString *)key ;
4545- (void )dataObject : (VSDataObject *)dataObject didChangeValueForKey : (NSString *)key ;
4646
47+ - (BOOL )dataObject : (VSDataObject *)dataObject getValue : (__strong id *)value forKey : (NSString *)key ;
48+ - (BOOL )dataObject : (VSDataObject *)dataObject setValue : (id )value forKey : (NSString *)key ;
49+
4750- (BOOL )dataManager : (VSDataManager *)dataManager eraseAllValuesForDataObject : (VSDataObject *)dataObject ;
4851- (BOOL )dataManager : (VSDataManager *)dataManager setAllValuesForDataObject : (VSDataObject *)dataObject ;
4952
Original file line number Diff line number Diff line change @@ -665,6 +665,51 @@ - (void)dataObject:(VSDataObject *)dataObject didChangeValueForKey:(NSString *)k
665665 }
666666}
667667
668+ - (BOOL )dataObject : (VSDataObject *)dataObject getValue : (__strong id *)value forKey : (NSString *)key
669+ {
670+ if (key == nil ) {
671+ return NO ;
672+ }
673+
674+ NSDictionary *properties = [self _propertiesForDataObjectClass: [dataObject class ]];
675+ VSDataObjectPropertyInfo *propInfo = nil ;
676+ if (properties == nil || (propInfo = [properties objectForKey: key]) == nil ) {
677+ return NO ;
678+ }
679+
680+ NSInvocation *invocation = [NSInvocation invocationWithMethodSignature: [propInfo getterSignature ]];
681+ [invocation setTarget: dataObject];
682+ [invocation setSelector: [propInfo getter ]];
683+ [invocation invoke ];
684+
685+ __unsafe_unretained id valueObject = nil ;
686+ [invocation getReturnValue: &valueObject];
687+ *value = valueObject;
688+
689+ return YES ;
690+ }
691+
692+ - (BOOL )dataObject : (VSDataObject *)dataObject setValue : (id )value forKey : (NSString *)key
693+ {
694+ if (key == nil ) {
695+ return NO ;
696+ }
697+
698+ NSDictionary *properties = [self _propertiesForDataObjectClass: [dataObject class ]];
699+ VSDataObjectPropertyInfo *propInfo = nil ;
700+ if (properties == nil || (propInfo = [properties objectForKey: key]) == nil ) {
701+ return NO ;
702+ }
703+
704+ NSInvocation *invocation = [NSInvocation invocationWithMethodSignature: [propInfo setterSignature ]];
705+ [invocation setTarget: dataObject];
706+ [invocation setSelector: [propInfo setter ]];
707+ [invocation setArgument: &value atIndex: 2 ];
708+ [invocation invoke ];
709+
710+ return YES ;
711+ }
712+
668713- (BOOL )dataManager : (VSDataManager *)dataManager eraseAllValuesForDataObject : (VSDataObject *)dataObject
669714{
670715 if ([dataObject dataManager ] != dataManager) {
Original file line number Diff line number Diff line change @@ -139,4 +139,21 @@ - (void)didChangeValueForKey:(NSString *)key withSetMutation:(NSKeyValueSetMutat
139139 [super didChangeValueForKey: key withSetMutation: mutationKind usingObjects: objects];
140140}
141141
142+ - (id )valueForKey : (NSString *)key
143+ {
144+ id value = nil ;
145+ if ([[VSDataModel sharedModel ] dataObject: self getValue: &value forKey: key]) {
146+ return value;
147+ }
148+
149+ return [super valueForKey: key];
150+ }
151+
152+ - (void )setValue : (id )value forKey : (NSString *)key
153+ {
154+ if (![[VSDataModel sharedModel ] dataObject: self setValue: value forKey: key]) {
155+ [super setValue: value forKey: key];
156+ }
157+ }
158+
142159@end
You can’t perform that action at this time.
0 commit comments