Vive Vive - 1 month ago 16
Swift Question

CMutablePointer - how to access it?

Can anybody explain how to access

CMutablePointer<CGPoint>
presented below? I can't find the syntax for it. It used to be
->
in
Objective-C
, 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

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.

Comments