In the UIScrollView delegate methods, there's:
scrollViewWillEndDragging:withVelocity:targetContentOffset:
and the last parameter is:
(inout CGPoint *)targetContentOffset
I'm curious as to what the inout means and why CGPoint is a pointer. I tried printing targetContentOffset to the console, but I'm not sure how to do so as well. Any help is appreciated!
It means the parameter is used to send data in
but also to get data out
.
Let's see an example implementation:
- (void)increment:(inout NSUInteger*)number {
*number = *number + 1;
}
NSUInteger someNumber = 10;
[self increment:&someNumber];
NSLog(@"Number: %u", someNumber); //prints 11
This pattern is often used with C structures, e.g CGPoint
because they are passed by value (copied).
Also note that inout
is not absolutely required there but it helps the compiler to understand the meaning of your code and do better job when optimizing.
There are also separate in
and out
annonations but as far as I know there are no compiler warnings when you misuse them and it doesn't seem Apple is using them any more.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With