• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: CoreData validation strangeness
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CoreData validation strangeness


  • Subject: Re: CoreData validation strangeness
  • From: mmalcolm crawford <email@hidden>
  • Date: Sat, 11 Mar 2006 12:57:30 -0800


On Mar 11, 2006, at 12:29 PM, Shaun Wexler wrote:

I'm seeing some strange behavior with a CoreData validation method.

It's not clear why this is specific to Core Data.
Have you checked to see if the validation method is being called when you expect it to be...



A bound text field validates immediately and updates continuously. I am fetching with a predicate to prevent duplicate entries, and want to check each character. If a match is found, NO is returned (it also returns a nil NSError). If the subsequent keypress is Backspace, no validation is performed?!! It appears that the NSArrayController or something else in KVO is caching the previous validation string incorrectly, because if I type "A", backspace, then "A" again, no validation is performed the 2nd time.

... a trivial test application doesn't display this behaviour...

Is this the correct behavior? I believe my logic is correct. The desired result is to bind the "OK" button enable to newAccountNameIsUnique, so that it is disabled for nil, zero- length, or like-matching an existing string:

I assume that the following methods are implemented in a subclass of NSManagedObject?


- (BOOL)validateNewAccountName:(id *)accountName error:(NSError **) outError
{
BOOL isValid;
if ((isValid = accountName && *accountName))
{
static NSFetchRequest *fetchRequest = nil;
if (!fetchRequest) {
fetchRequest = [[NSFetchRequest alloc] init];
[fetchRequest setEntity:[NSEntityDescription entityForName:@"Account" inManagedObjectContext:[self managedObjectContext]]];


            [fetchRequest setEntity:[self entity]];


}
[fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"accountName like[cd] %@", *accountName]];


It is much more efficient to create a predicate template and substitute values than to re-parse the format string each time.


- (NSString *)newAccountName
- (void)setNewAccountName:(NSString *)name

It's not clear why these methods don't follow the prescribed form for managed object accessors?

mmalc

_______________________________________________
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


  • Follow-Ups:
    • Re: CoreData validation strangeness
      • From: Shaun Wexler <email@hidden>
    • Re: CoreData validation strangeness
      • From: Shaun Wexler <email@hidden>
References: 
 >CoreData validation strangeness (From: Shaun Wexler <email@hidden>)

  • Prev by Date: Re: Navigating a TableView: A Solution
  • Next by Date: Re: Getting local timezone as integer
  • Previous by thread: CoreData validation strangeness
  • Next by thread: Re: CoreData validation strangeness
  • Index(es):
    • Date
    • Thread