• 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: Simple question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Simple question


  • Subject: Re: Simple question
  • From: Arnold Nefkens <email@hidden>
  • Date: Thu, 22 Apr 2010 19:21:51 +0200

Hi Thanks

Yeah the keys are ints and this helps a lot.

Thanks again...


On 22 apr 2010, at 18:31, Reinhard Segeler wrote:

> Hi,
>
> correct me if I'm wrong, but what you're doing is a calculation with the pointers ( * of NSNumber) not the values. You have to calculate it like this:
>
> NSInteger fieldOne 	= [ [ managedObject valueForKey:@"key1"] intValue]; // if it's an integer
> NSInteger  fieldTwo 	= [ [ managedObject valueForKey:@"key2"] intValue];
> NSInteger  fieldThree = [ [ managedObject valueForKey:@"key3"] intValue];
>
> if ( fieldTwo > 0 )
> {
> 	NSNumber *answer = [ NSNumber numberWithInt:fieldTwo - fieldOne + fieldThree];
> 	[ self.managedObject setValue:answer forKey:@"key4"];
> 	// maybe you need to this instead
> 	[ self.managedObject setValue:[ answer stringValue] forKey:@"key4"];
> }
>
> Don't know if intValue in this context works, if not then use this alternative, which must work in any way:
>
> Your code and change the following lines:
>
> NSNumber *answer = [ NSNumber numberWithInt: [fieldTwo intValue] - [fieldOne intValue] + [fieldThree intValue] ];
>
> 	[ self.managedObject setValue:answer forKey:@"key4"];
> 	//or
> 	[ self.managedObject setValue:[ answer stringValue] forKey:@"key4"];
> 	//stringValue to present it in a textfield
>
> Hope that helped... MacMeideln
>
> Am 22.04.2010 um 17:36 schrieb Arnold Nefkens:
>
>> Hello list,
>>
>> Im quite new, and probably missing something.
>>
>> I want to do a calculation of three fields inside of a entity in CoreData.
>>
>> Below is the code, what is wrong?
>>
>> NSNumber *fieldOne = [managedObject valueForKey:@"key1"];
>> NSNumber *fieldTwo = [managedObject valueForKey:@"key2"];
>> NSNumber *fieldThree = [managedObject valueForKey:@"key3"];
>> if (fieldTwo > 0) {
>> 	NSNumber *answer = ((fieldTwo - fieldOne) + fieldThree);
>> 	[self.managedObject setValue:[answer intValue] forKey:@"key4"];
>> }
>>
>> If I debug the right values are being shown in the fieldOne, fieldTwo and fieldThree. But the calculation answer is all the time out of scope.....
>>
>> What am I missing?
>>
>> hope someone can help...
>>
>> Arnold Nefkens_______________________________________________
>>
>> 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
>

_______________________________________________

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: Simple question
      • From: Quincey Morris <email@hidden>
    • Re: Simple question
      • From: James Montgomerie <email@hidden>
    • Re: Simple question
      • From: banane <email@hidden>
References: 
 >Simple question (From: Arnold Nefkens <email@hidden>)
 >Re: Simple question (From: Reinhard Segeler <email@hidden>)

  • Prev by Date: Re: Simple question
  • Next by Date: Re: Simple question
  • Previous by thread: Re: Simple question
  • Next by thread: Re: Simple question
  • Index(es):
    • Date
    • Thread