Re: Correct way to implement validateValue:?
Re: Correct way to implement validateValue:?
- Subject: Re: Correct way to implement validateValue:?
- From: Keith Blount <email@hidden>
- Date: Sat, 25 Jun 2005 13:28:52 -0700 (PDT)
Many thanks again for your reply, I really appreciate
all your help.
There is indeed no reason why I couldn't give my model
a title accessor - I had completely overlooked this.
(I had originally wrongly assumed that the
validateValue:forKeyPath:error method would use the
keyPath to check for changes in a dictionary object,
which is where my initial mistake lay.)
Given that I have to check that whether or not a file
is on disk, though - which would mean that my model
would have to know the path to the saved project file,
which seems bad-MVC practise - I have taken your
advice and gone the controller route.
My new solution is that I am overriding
-textShouldEndEditing: in an NSOutlineView subclass
and asking the delegate to validate the edit. If my
delegate method returns NO, I simply return YES for my
-textShouldEndEditing: method, which ends editing
without changing the string. If my delegate method
returns YES, I return [super
textShouldEndEditing:textObject], so that super sorts
out changing the string and ending editing. This
solution seems to work well, as it leaves all
responsibility for validating the change with the
controller, which already knows where the file is
stored on disk... (If this is a silly solution, I
would be grateful if you would tell me so!)
Many thanks again,
Keith
---
FROM : mmalcolm crawford
DATE : Sat Jun 25 20:45:08 2005
On Jun 25, 2005, at 7:35 AM, Keith Blount wrote:
>>> Given the situation, this is probably best done at
>>> the controller level...
> Given that I am using nested objects, what is the
best
> way to do this? I have been using straightforward
KVO
> - registering my controller as the observer of the
> "title" key of the model's properties dictionary
>
Do you need to do this in your model class, or can you
simply
validate values as they're entered in the UI (as you
seemed to imply
here:
> Also, is this even the best approach when what I
> actually want to do is to check that the file being
> renamed doesn't already exist on disk? Shouldn't I
> really be doing this in my controller rather than my
> model?
)? Whilst less "academically pure" than putting
validation logic
into the model, this would seem to be a rather easier
pragmatic
solution. Alternatively, is there any reason why the
"title"
attribute must be stored in a dictionary, or at least
why you cannot
provide accessor methods that abstract the attribute?
- (NSString *)title
{
return [propertiesDictionary
objectForKey:@"title"];
}
- (void)setTitle:(NSString *)newTitle
{
[propertiesDictionary setObject:newTitle
forKey:@"title"];
}
You could then readily implement a
validateTitle:error: method...
mmalc
__________________________________
Do you Yahoo!?
Yahoo! Mail - Find what you need with new enhanced search.
http://info.mail.yahoo.com/mail_250
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden