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
fi...@code2develop.com


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/filip%40code2develop.com

This email sent to fi...@code2develop.com

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to