ios - 更改委托(delegate)方法的参数类型

标签 ios objective-c delegates nsinteger nsuinteger

我有一个 NSURL 委托(delegate)方法,它接受 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 

我的问题是是否可以进行这样的更改?到目前为止我没有遇到任何问题,正在调用该方法并且我得到了预期的结果。

我担心可能会发生一些无法预料的问题。

最佳答案

这样做很好。将 NSInteger 更改为 NSUInteger 仅执行普通转换。但是,我会将 NSInteger 保留为方法参数,然后在方法实现开始时将其显式转换为 NSUInteger

关于ios - 更改委托(delegate)方法的参数类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15209896/

相关文章:

objective-c - IOS,删除警告?

ios - Swift 中的 Facebook 游戏请求

objective-c - EXC_BAD_ACCESS 在初始化时在自定义类上设置属性时?

c# - 为一个事件查询一名委托(delegate)两次

c# - 需要知道如何在 Xamarin.iOS 中终止后台进程

objective-c - 上传新的 iPad 应用程序版本 : "iPad: application executable contains unsupported architecture(s): i386" 时出错

iphone - 从 URL 获取 XML 文件到 NSData 对象?

ios - 使用 AFNetworking 3.0 从 URL 设置 TableView Cell 图像(异步)

c# - 为什么编码回调委托(delegate)结构会导致 AccessViolationException

C# 委托(delegate)和函数调用