• 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: mmalc crawford <email@hidden>
  • Date: Wed, 27 Aug 2008 21:32:17 -0700


On Aug 27, 2008, at 9:00 PM, 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.


This is expected and desirable behaviour.

I was wondering if there was a more direct and less glue-code involving way of doing this.

This isn't "glue code", this is "business logic". It's not possible to determine a priori how a scalar value should represent null, so you need to implement this method to tell your model objects how you want them to represent one.

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.

Why not? There may be an advantage if you are doing a lot of mathematical calculations, but the disadvantage is that you have to convert between object and scalar values for the user interface. If you haven't already, you should profile your application to be sure you're not prematurely optimising.

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

Not directly. You could implement a value transformer to turn a nil value into a number 0, or (best of all) you could use a formatter to prevent a user from entering a nil in the first place...

mmalc

_______________________________________________

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>
    • Re: Bindings and empty text field nil assigments
      • From: mmalc crawford <email@hidden>
References: 
 >Bindings and empty text field nil assigments (From: Markus Spoettl <email@hidden>)

  • Prev by Date: Get current amount of available RAM
  • Next by Date: Re: Get current amount of available RAM
  • Previous by thread: Re: Bindings and empty text field nil assigments
  • Next by thread: Re: Bindings and empty text field nil assigments
  • Index(es):
    • Date
    • Thread