Vive Vive - 9 months ago 70
Swift Question

CMutablePointer - how to access it?

Can anybody explain how to access

presented below? I can't find the syntax for it. It used to be
, but here none of my solutions works. The solution presented in this link works in the opposite way I need to find out.

func scrollViewWillEndDragging(scrollView: UIScrollView!, withVelocity velocity: CGPoint, targetContentOffset: CMutablePointer<CGPoint>) {
let newPage = targetContentOffset->x + 1;

Answer Source

You can use inout targetContentOffset: CGPoint in place of targetContentOffset: CMutablePointer<CGPoint> to access it like a regular CGPoint. Much more readable!

Since Swift beta 5, scrollViewWillEndDragging has taken an UnsafeMutablePointer<CGPoint>. As recommended by @Jared, the underlying CGPoint should be accessed / updated through the memory property of the pointer.

Starting with Swift 3, the memory property has been renamed pointee.