• 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: NSNull and distinct objective-C type
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSNull and distinct objective-C type


  • Subject: Re: NSNull and distinct objective-C type
  • From: Filip van der Meeren <email@hidden>
  • Date: Thu, 4 Jun 2009 14:42:59 +0200


On 04 Jun 2009, at 14:31, Steven Hamilton wrote:

Hi folks,
I need some advice on how best to handle an itchy problem. In order to tighten up my coding I'm compiling with warnings as errors which has showed up a big problem with my code.


I have a tableView using a datasource array of dictionaries. Fairly standard stuff. 2 of the keys in this dictionary are "credit" and "debit". When I process the data only one of these can be set, the other has to be nil or NSNull. I test against this later on when manipulating the data. My problem appeared when I I turned on warning as errors. I kept getting the following;

if ([amount floatValue] < 0){
	NSString *amountString = [[amount stringValue] substringFromIndex:1];
		debit = [NSDecimalNumber decimalNumberWithString:amountString];
		credit = [NSNull null];
		warning: assignment from distinct Objective-C type

You can not assign null to an NSNumber, NSNull is of another type.
You could of course change the variabletype of credit to "id" instead of NSNumber, then the NSNull would work. It doesn't change much at all, the compiler replaces your NSNumber with id anyway. It just "allows" you to use NSNumber for static type checking.



} else { credit = amount; debit = [NSNull null]; warning: assignment from distinct Objective-C type } }

I thought I'd be smart and change the NSNull to nil instead but of course that terminates the dictionary early when I come to create it.

NSMutableDictionary *transdic = [NSMutableDictionary dictionaryWithObjectsAndKeys:date, @"date", memo, @"memo", transferIndex, @"transferIndex", credit, @"credit", debit, @"debit", nil];

I'm getting the error because I initially declared my credit and debit objects as NSNumbers. Can I recast them without them losing scope?


Filip van der Meeren
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

_______________________________________________

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


References: 
 >NSNull and distinct objective-C type (From: Steven Hamilton <email@hidden>)

  • Prev by Date: Re: NSNull and distinct objective-C type
  • Next by Date: Help with SHA class
  • Previous by thread: Re: NSNull and distinct objective-C type
  • Next by thread: Re: NSNull and distinct objective-C type
  • Index(es):
    • Date
    • Thread