NSNull and distinct objective-C type
NSNull and distinct objective-C type
- Subject: NSNull and distinct objective-C type
- From: Steven Hamilton <email@hidden>
- Date: Thu, 4 Jun 2009 22:31:01 +1000
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
} 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?
_______________________________________________
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