Setting up bindings using GC and properties
Setting up bindings using GC and properties
- Subject: Setting up bindings using GC and properties
- From: Sam Stigler <email@hidden>
- Date: Fri, 2 Nov 2007 22:52:25 -0700
Hi,
I've been trying to get the hang of this for the past several hours,
but I still can't get it right: What is the correct way to initialize
(by which I mean set an initial value) for a binding in a project
using garbage collection and properties? I think I'm following the
examples fairly well, but I keep on getting
"__TERMINATING_DUE_TO_UNCAUGHT_EXCEPTION__" errors saying that my
class isn't KVC-compliant for a given property.
(By "the examples" I mean the sample code found in the documentation
about properties in "The Objective-C 2.0 Programming Language"
documentation; as well as two helpful sample projects posted by
mmalc: BindingsDocumentInspector and ToDos.)
In my current project, I'm trying to bind an NSMutableDictionary to
the "Content Dictionary" binding of an NSDictionaryController, using
the model key path "serverStatus". I've declared the dictionary and
its setters and getters with the following:
NSMutableDictionary *serverStatus; [.....] @property(copy,
readwrite) NSMutableDictionary *serverStatus;
I tried two different kinds of implementations for the property:
First I tried using @dynamic with my own mutableCopy setter method,
but when that gave me the KVC compliance error I reverted back to
@synthesize. That again, gave me the same error.
I'm initializing the dictionary in my init method... is that the
right way to do it? Here's what my init method looks like:
- (id)init
{
self = [super init];
if (self != nil) {
// Need to create URL with current IP address and port number:
NSURL *me = [NSURL URLWithString:[NSString stringWithFormat:@"http://
%@:%i",[[NSHost currentHost] ipv4Address], 5432]];
[self setServerStatus:[NSMutableDictionary
dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO],@"started",
[NSMutableArray arrayWithCapacity:10],@"previousCommandsSent",
me,@"myAddress", [NSMutableArray arrayWithCapacity:
5],@"currentlyConnectedControllers", @"off",@"bonjourOnOff", nil]];
}
return self;
}
(-ipv4Address is from a category of NSHost. It returns a string.)
Each time I try to Build and Run the app, I get an exception that the
class is not KVC-compliant for "bonjourOnOff". The relevant text
field's binding is to the dictionary controller in question, with
controller key "selection", model key path "bonjourOnOff", and my own
custom value transformer. I've checked the spelling, and it looks
like there are no mistakes there.
Does anyone have any idea what I could be doing wrong here, or some
guidance on what the right way is to initialize bindings under GC?
(For example, right now I'm using an autoreleased
NSMutableDictionary... should I be using an autoreleased one (I know
the examples do), or just a nested alloc and init and let GC take care
of the release, like the ToDos example does for value transformers?)
I'm completely confused here.
Thanks,
Sam
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden