【发布时间】:2013-03-04 19:49:46
【问题描述】:
我有一个以 NSInteger 作为参数的 NSURL 委托方法
- (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
我的问题是是否可以进行这样的更改?到目前为止,我还没有遇到任何问题,正在调用该方法并且我得到了预期的结果。
我担心可能会发生一些无法预料的问题。
【问题讨论】:
-
您如何获得超出范围的值?你真的在一个写入块中发送了超过 2GB 的数据?
-
totalBytesExpectedToWrite 有时会超过 2 GB
-
抱歉,我滚动的不够多。我只看了
bytesWritten参数。
标签: ios objective-c delegates nsinteger nsuinteger