Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMutablePointer - how to access it?

Tags:

swift

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;  } 
like image 791
Nat Avatar asked Jun 06 '14 12:06

Nat


2 Answers

As @Eric mentioned in his update, the scrollViewWillEndDragging delegate now takes an UnsafePointer. To update the Unsafe pointer, you just have to access the memory property.

func scrollViewWillEndDragging(scrollView: UIScrollView!, withVelocity velocity: CGPoint, targetContentOffset: UnsafePointer<CGPoint>) {     targetContentOffset.memory.y = x + 1 } 

*Tested and working with Swift Beta 4.

UPDATED FOR BETA 5
Swift Beta 5 scroll view delegate uses an UnsafeMutablePointer instead of UnSafePointer

func scrollViewWillEndDragging(scrollView: UIScrollView!, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {     targetContentOffset.memory.y = x+ 1 } 
like image 73
Jared Messenger Avatar answered Oct 05 '22 15:10

Jared Messenger


Since Swift beta 5, scrollViewWillEndDragging(_:withVelocity:targetContentOffset:) has taken an UnsafeMutablePointer instance as its last argument. When this method is called by your scroll view, your implementation can access the underlying Core Graphics point through the pointer's pointee property.

Note that the spelling of pointee used to be memory before Swift 3.

like image 24
Erik Foss Avatar answered Oct 05 '22 13:10

Erik Foss