• 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: Bindings and empty text field nil assigments
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bindings and empty text field nil assigments


  • Subject: Re: Bindings and empty text field nil assigments
  • From: Quincey Morris <email@hidden>
  • Date: Wed, 27 Aug 2008 21:21:08 -0700

On Aug 27, 2008, at 21:00, Markus Spoettl wrote:

I have objects storing simple scalar values (NSInteger, double). Those values/properties are bound to text fields. Now, if the user clears the text field and the underlying property gets updated, it's not simply setting the value to 0 or its equivalent, instead

- (void)setNilValueForKey:(NSString *)key

is invoked. Failing to implement it causes an exception when exiting out of a cleared text field bound to a scalar value.

I was wondering if there was a more direct and less glue-code involving way of doing this. I don't want to go and store NSNumbers instead of scalar values, which I imagine would have the advantage of accepting nil values inherently.

Can I tell the bindings system to directly set scalars to 0 in case of nil values?

I suspect you can get the effect you want by using a formatter on the text field. Someone was complaining on this list a week or two ago that 10.4+ style formatters never set properties to nil values, but this sounds like the behavior you want.


There's another reason you should generally be using formatters. Without them, the value of the text field gets sent *as a string*, which eventually gets converted to a scalar with [NSString integerValue] or [NSString doubleValue] (etc). Unfortunately, there's no [NSString unsignedIntegerValue] (etc) so if your property is type NSUInteger (etc) the conversion will throw an exception.

When you use formatters, the value of the text field gets sent as a NSNumber, which supports all the conversions to a scalar.


_______________________________________________

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


  • Follow-Ups:
    • Re: Bindings and empty text field nil assigments
      • From: Markus Spoettl <email@hidden>
References: 
 >Bindings and empty text field nil assigments (From: Markus Spoettl <email@hidden>)

  • Prev by Date: Bindings and empty text field nil assigments
  • Next by Date: Re: global key bindings
  • Previous by thread: Bindings and empty text field nil assigments
  • Next by thread: Re: Bindings and empty text field nil assigments
  • Index(es):
    • Date
    • Thread