2013-03-04 116 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