[baseten-users] Notifications
Michael Ruepp
MICHAEL at RUEPP.AT
Thu Oct 8 16:22:32 EEST 2009
Hi all,
I need some help regarding baseten notifications.
Challenge:
1. I have a GUI only App with a one to many relationship: Group ->
Persons
Group has the Properties
name (String)
modified (BOOL)
Persons has the Properties
name (String)
preName (String)
lastName (String)
dateCreated
modified (BOOL)
I want to achieve, that when I change something in the Persons Table,
that the Group.modified property changes to YES (or whatsoever).
I want to achieve that when I change wether preName or lastName, that
the name Property changes to "preName_lastName".
I thought about ValueTransformers, but arent they just for display
purposes?
I tried with subclassing of BXManagedObject and put it in the Custom
Class Name of the BXSynchronisedArrayController Object in IB, then
bind the Value of the respective Column to the function setName, it
works occasionally, but when I connect the second Time I get:
08.10.09 12:03:40 FCL_01[32257] Cocoa Bindings: Error accessing value
for key path name of object <BXDatabaseObject (0x20021d3a0) pgsql://sunrise-big.local/fuse/public/files?id,n=1
fault: 1> (from bound object <NSTableColumn: 0x20009c520>
identifier: (null) with object ID 1001 in nib named MainMenu.nib):
[<BXDatabaseObject 0x20021d3a0> valueForUndefinedKey:]: this class is
not key value coding-compliant for the key name.
The Code:
@interface PersonsBO : BXDatabaseObject {
BXDatabaseContext* ctx_delegate_;
}
@property (nonatomic, retain) NSString *name;
@property (nonatomic, readonly) NSString *preName;
@property (nonatomic, readonly) NSString *lastName;
- (NSString*)setName;
@end
@implementation PersonsBO
@dynamic name;
@dynamic preName;
@dynamic lastName;
-(void)awakeFromInsert {
[self setValue:[NSDate date] forKey:@"dateCreated"];
}
- (NSString *)setName {
NSError* error = nil;
if (self.name != nil) {
return self.name;
}
if (self.preName == nil || self.lastName == nil) {
[self setValue:@"untitled" forKey:@"name"];
[ctx_delegate_ save:&error];
return [NSString stringWithFormat:@"No Name"];
}
[self setValue:[NSString stringWithFormat:@"%@ %@", self.preName,
self.lastName] forKey:@"name"];
return [NSString stringWithFormat:@"%@.%@", self.preName,
self.lastName];
}
2. Code only:
I successfully created a BXSynchronisedArrayController in my Model
Class (at Init). How can I track the Controller for Object changes
which returns me the specific Object, which changed?
group_ = [[BXSynchronizedArrayController alloc]init];
[group_ setEntityDescription:[context_ entityForTable: @"group"
error: NULL]];
[group_ setTableName:@"group"];
[group_ setFetchesAutomatically:YES];
[group_ setDatabaseContext:context_];
[group_ fetchWithRequest:nil merge:YES error:&error];
I receive already Notifications, but they just return the
BXEntitiyDescription as stated in the Manual. But I need the specific
Object to set the Modified BOOL of the specific container Group to YES.
//Establish Notification for Context and change Root Modified date
on occurness of directory changes
NSNotificationCenter* ctx_ns_center = [context_ notificationCenter];
NSLog(@"Ctx ns center: %@",(NSString*)ctx_ns_center);
[ctx_ns_center addObserver:self
selector:@selector(contextChanged:)
name:kBXInsertNotification object:nil];
[ctx_ns_center addObserver:self
selector:@selector(contextChanged:)
name:kBXUpdateNotification object:nil];
[ctx_ns_center addObserver:self
selector:@selector(contextChanged:)
name:kBXDeleteNotification object:nil];
with this function (but I dont know the specific Object which changed):
-(void)contextChanged:(NSNotification *)notification
{
if (![notification name]) {
return;
}
[self doSomething]];
NSLog(@"Context received message = %@",[notification name]);
}
How can I achieve this with KVO? I should not add an observer for a
specific key path, but should observe the whole
BXSynchronisedArrayController for changes and trigger a function which
receive as parameter the BXDatabaseObject which changed.
I tried this in the init section (When I try without
"toObjectsAtIndexes:",
then I get a error message:
"08.10.09 15:02:41 FSRV_RW_01[34467] [<NSCFArray 0x2000732c0>
addObserver:forKeyPath:options:context:] is not supported. Key path:
group :"
groupContainer_ = [context_ executeFetchForEntity: [context_
entityForTable: @"group" error: NULL] withPredicate: nil
excludingFields:nil updateAutomatically:YES error: NULL];
[groupContainer_ setOwner:self];
[groupContainer_ setKey:@"groupChanged"];
NSIndexSet *allIndexes = [NSIndexSet
indexSetWithIndexesInRange:NSMakeRange(0, [groupContainer_ count])];
[groupContainer_ addObserver:self toObjectsAtIndexes:allIndexes
forKeyPath:@"group" options:0 context:@"groupChanged"];
with this:
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(void *)context {
NSLog(@"Observer KeyPath %@",keyPath);
if ([keyPath isEqual:@"groupChanged"]) {
[self doSomething];
}
}
But I dont get any notification from KVO!
Thanks very much for help,
Mike
_________________
michael ruepp
michael at ruepp.at
fon +41 76 593 04 49
skype michaelruepp
CONFIDENTIALITY NOTICE
This message (including any attachments transmitted with it) contains
confidential information and is intended only for the individual named
herein. If you are not the herein named addressee you should not
disseminate, distribute, copy or otherwise make use of this message.
Please notify the sender immediately by e-mail if you have received
this message by mistake, and delete it from your systems.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.basetenframework.org/pipermail/baseten-users/attachments/20091008/aabea414/attachment-0001.htm>
More information about the baseten-users
mailing list