2013-03-04 188 views
3

我有一个NSURL委托方法这需要在NSInteger的作为参数的委托方法

- (void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite 

NSInteger的是一份署名长更改参数类型的范围为-2147483647到2147483647。我的问题是,有时我我得到的数值超过了正数范围,这导致数值变成了我不想要的负数。

所以我改变了NSInteger的到NSUInteger

- (void)connection:(NSURLConnection *)connection didSendBodyData:(NSUInteger)bytesWritten totalBytesWritten:(NSUInteger)totalBytesWritten totalBytesExpectedToWrite:(NSUInteger)totalBytesExpectedToWrite 

我的问题是,它是否是确定做出这样的改变?到目前为止我还没有任何问题,该方法正在调用,我正在得到预期的结果。

我担心可能发生的一些不可预见的问题。

+0

你怎么能得到超出范围的价值?您真的在单个写入块中发送了2GB以上的数据? – rmaddy 2013-03-04 19:52:56

+0

totalBytesExpectedToWrite有时会超过2 GB – user1861763 2013-03-04 19:54:47

+0

对不起,我没有足够的滚动。我只查看了'bytesWritten'参数。 – rmaddy 2013-03-04 19:57:10

回答

0

这样做很好。将NSInteger更改为NSUInteger仅执行普通铸造。但是,我会保留NSInteger作为方法参数,然后我会在方法实施开始时将其明确地转换为NSUInteger