It's fine to do this. Changing NSInteger
to NSUInteger
performs just an ordinary casting. However, I would keep NSInteger
as a method parameter and then I would cast it explicitly at the beginning of method implementation to NSUInteger
.
Changing Parameter Type for Delegate Methods
-
18-03-2022 - |
Question
I have a NSURL delegate method which takes in NSInteger as the parameter
- (void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite
NSInteger which is a signed long has a range of -2147483647 to 2147483647. My issue is that sometimes i am getting values which exceed the positive range and this causes the value to go to a negative number which i don't want.
So i changed the NSInteger to NSUInteger
- (void)connection:(NSURLConnection *)connection didSendBodyData:(NSUInteger)bytesWritten totalBytesWritten:(NSUInteger)totalBytesWritten totalBytesExpectedToWrite:(NSUInteger)totalBytesExpectedToWrite
My question is whether it is ok to make such a change ? I haven't had any issues so far, the method is being called and i am getting the expected results.
I am concerned about some unforeseen issues that might occur.
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow