gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:43:02 27 4
gpt4 key购买 nike

我有一个 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com