3

NSIntegerをパラメーターとして受け取るNSURLデリゲートメソッドがあります

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

符号付きlongであるNSIntegerの範囲は-2147483647〜2147483647です。私の問題は、正の範囲を超える値を取得することがあり、これにより値が不要な負の数になることです。

だから私はNSIntegerをNSUIntegerに変更しました

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

私の質問は、そのような変更を行っても大丈夫かどうかです。これまでのところ問題はありません。メソッドが呼び出され、期待どおりの結果が得られています。

予期せぬ問題が発生する可能性があります。

4

1 に答える 1

0

これを行うのは問題ありません。に変更NSIntegerするNSUIntegerと、通常のキャストが実行されます。ただし、NSIntegerメソッドパラメータとして保持し、メソッド実装の開始時に明示的ににキャストしNSUIntegerます。

于 2013-03-04T20:32:57.760 に答える