• 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
Bindings, NSNumber equal to NIL and performing mathematical operations issue
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bindings, NSNumber equal to NIL and performing mathematical operations issue


  • Subject: Bindings, NSNumber equal to NIL and performing mathematical operations issue
  • From: Eric Hochmeister <email@hidden>
  • Date: Thu, 5 May 2005 17:52:17 -0400

Hi all,

I'm using bindings and I'm having an issue with binding a NSNumber up
to an NSTextField and using this NSNumber to perform mathematical
operations.

ie.  I have a simple example, two textfields which are bound to two
NSNumber attributes and another textfield which displays the result of
these two NSNumbers multiplied together.

My issue arises, when I enter valid inputs into both textfields, ie.
10 and 10.. the result is 100... but if I delete 10 from one of the
textfields, the result still stays 100.  But if I change the textfield
back to another number it is updated correctly.  The issue I'm seeing
is that when my NSNumber is set to nil, and I ask [NSNumber
doubleValue] it's giving me not 0... causing my calculation to be
wrong.

I've pasted my result method below.  num1 and num2 are both bound to
the textfield, and result is setup to be updated when num1 or num2
change...

ie. 	[self setKeys:[NSArray arrayWithObjects:@"num1",@"num2",nil]
 triggerChangeNotificationsForDependentKey:@"result"];

Any ideas?  What I want is that if nothing is entered in the textfield
instead of saving nil, 0 is saved and the textfield is updated to
display 0 as well.

- (NSNumber*)result;
{
	double n1 = [[self num1] doubleValue];
	double n2 = [[self num2] doubleValue];
	double aTotal = n1 * n2;

	return [NSNumber numberWithDouble:aTotal];
}

Thanks,

Eric
 _______________________________________________
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: Bindings, NSNumber equal to NIL and performing mathematical operations issue
      • From: Bob Ippolito <email@hidden>
    • Re: Bindings, NSNumber equal to NIL and performing mathematical operations issue
      • From: Ricky Sharp <email@hidden>
  • Prev by Date: Re: 10.3.9 build errors "Carbon headers missing" ??
  • Next by Date: Handling open as a result of spotlight search
  • Previous by thread: Re: NSOutlineView problem
  • Next by thread: Re: Bindings, NSNumber equal to NIL and performing mathematical operations issue
  • Index(es):
    • Date
    • Thread