Re: NSNull and distinct objective-C type

2009-06-04 Thread Graham Cox


On 04/06/2009, at 10:31 PM, Steven Hamilton wrote:

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



Yes, just do this: credit = (id)[NSNull null];

--Graham


___

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


Re: NSNull and distinct objective-C type

2009-06-04 Thread Steven Hamilton


On 04/06/2009, at 10:36 PM, Graham Cox wrote:



On 04/06/2009, at 10:31 PM, Steven Hamilton wrote:

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



Yes, just do this: credit = (id)[NSNull null];

--Graham



Genius! I can now go to bed happy. Thanks a lot.

___

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


Re: NSNull and distinct objective-C type

2009-06-04 Thread Filip van der Meeren


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


Re: NSNull and distinct objective-C type

2009-06-04 Thread harpreet_singh
Hello All,

I am facing an issue in use of mach_absolute_time().

mach_absolute_time() gives drift even when NTP timing update is on.

Please see my code below:

#import 
#import 
nt main(int argc, char *argv[])
{
uint64_t nowTime = mach_absolute_time();
uint64_t drift = 0;
for (int i=0;i<1000;i++)
{
sleep(5);
uint64_t current_Time = mach_absolute_time();
uint64_t differenceTime = (current_Time - nowTime)*1E-6;
drift = differenceTime - (i+1)*5000;
NSLog(@"Elapsed Time =%lld",differenceTime);
NSLog(@"drift =%lld",drift);
}
return 1;
//return NSApplicationMain(argc,  (const char **) argv);
}

Expected Results:
 I expected to see zero drift in the print. After several runs, the drift
kept on increasing

Actual Results:
Below are actual results
009-06-04 17:49:49.936 TestMachSleep[3275:10b] Elapsed Time =5000
2009-06-04 17:49:49.939 TestMachSleep[3275:10b] drift =0
2009-06-04 17:49:54.940 TestMachSleep[3275:10b] Elapsed Time =10004
2009-06-04 17:49:54.942 TestMachSleep[3275:10b] drift =4
2009-06-04 17:49:59.943 TestMachSleep[3275:10b] Elapsed Time =15007
2009-06-04 17:49:59.944 TestMachSleep[3275:10b] drift =7
2009-06-04 17:50:04.947 TestMachSleep[3275:10b] Elapsed Time =20011
2009-06-04 17:50:04.950 TestMachSleep[3275:10b] drift =11
2009-06-04 17:50:09.954 TestMachSleep[3275:10b] Elapsed Time =25018
2009-06-04 17:50:09.965 TestMachSleep[3275:10b] drift =18
2009-06-04 17:50:14.976 TestMachSleep[3275:10b] Elapsed Time =30040
2009-06-04 17:50:14.991 TestMachSleep[3275:10b] drift =40
2009-06-04 17:50:20.003 TestMachSleep[3275:10b] Elapsed Time =35068
2009-06-04 17:50:20.004 TestMachSleep[3275:10b] drift =68
2009-06-04 17:50:25.012 TestMachSleep[3275:10b] Elapsed Time =40076
2009-06-04 17:50:25.031 TestMachSleep[3275:10b] drift =76
2009-06-04 17:50:30.041 TestMachSleep[3275:10b] Elapsed Time =45105
2009-06-04 17:50:30.046 TestMachSleep[3275:10b] drift =105
2009-06-04 17:50:35.064 TestMachSleep[3275:10b] Elapsed Time =50129
2009-06-04 17:50:35.073 TestMachSleep[3275:10b] drift =129
2009-06-04 17:50:40.091 TestMachSleep[3275:10b] Elapsed Time =55156
2009-06-04 17:50:40.092 TestMachSleep[3275:10b] drift =156
2009-06-04 17:50:45.104 TestMachSleep[3275:10b] Elapsed Time =60169
2009-06-04 17:50:45.112 TestMachSleep[3275:10b] drift =169
2009-06-04 17:50:50.133 TestMachSleep[3275:10b] Elapsed Time =65198
2009-06-04 17:50:50.136 TestMachSleep[3275:10b] drift =198
2009-06-04 17:50:55.137 TestMachSleep[3275:10b] Elapsed Time =70202
2009-06-04 17:50:55.138 TestMachSleep[3275:10b] drift =202
2009-06-04 17:51:00.147 TestMachSleep[3275:10b] Elapsed Time =75212
2009-06-04 17:51:00.160 TestMachSleep[3275:10b] drift =212


I need millisecond accuracy to send time to server after certain activity
has been done. I understand that sleep is not millisecond accurate but I
was not expecting to see a progressively increasing drift.




___

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


Re: NSNull and distinct objective-C type

2009-06-04 Thread I. Savant
On Thu, Jun 4, 2009 at 8:39 AM,   wrote:

> I am facing an issue in use of mach_absolute_time().

  Your post is off-topic in two ways: First, this has nothing to do
with the thread to which you replied (start a new thread for a new
question/topic). Second, this has nothing to do with Cocoa at all
(post to lists appropriate to your topic ... mach_absolute_time() is
not part of Cocoa - maybe the darwin-dev list would be a better place
to ask).

  Take a look at http://www.lists.apple.com/mailman/listinfo for a
list of lists hosted by Apple or use Google to find appropriate lists.

--
I.S.
___

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


Re: NSNull and distinct objective-C type

2009-06-04 Thread David Duncan

On Jun 4, 2009, at 5:39 AM, harpreet_si...@oxyent.com wrote:


Hello All,

I am facing an issue in use of mach_absolute_time().

mach_absolute_time() gives drift even when NTP timing update is on.

sleep(5);


Your assuming that sleep() provides drift free timing, which it does  
not - read the man page x-man-page://3/sleep for details.


If you want something closer to a drift free timer, then you need to  
determine when you want to wake up and use mach_wait_until() or a  
higher level API to wait until that time.

--
David Duncan
Apple DTS Animation and Printing

___

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