ios – 如何在swift中创建UnsafeMutablePointer对象

ios – 如何在swift中创建UnsafeMutablePointer对象,第1张

概述我需要调用UIScrollViewDelegate方法,我不知道如何创建UnsafeMutablePointer对象. let pointer:UnsafeMutablePointer<CGPoint> = CGPoint(x: 0, y: 1) as! UnsafeMutablePointer<CGPoint>self.scrollViewWillEndDragging(self.coll 我需要调用uiscrollviewdelegate方法,我不知道如何创建UnsafeMutablePointer对象.

let pointer:UnsafeMutablePointer<CGPoint>  = CGPoint(x: 0,y: 1) as! UnsafeMutablePointer<CGPoint>self.scrollVIEwWillEndDragging(self.collectionVIEw,withVeLocity: CGPoint(x: 0,y: 1),targetContentOffset: pointer)func scrollVIEwWillEndDragging(scrollVIEw: UIScrollVIEw,withVeLocity veLocity: CGPoint,targetContentOffset: UnsafeMutablePointer<CGPoint>) {       //Some code here}
解决方法
import Foundationvar point = CGPoint(x: 10.0,y: 20.0)let p = withUnsafeMutablePointer(&point) { (p) -> UnsafeMutablePointer<CGPoint> in    return p}print(p.memory.x,p.memory.y) // 10.0 20.0point.x = 100.0print(p.memory.x,p.memory.y) // 100.0 20.0

借助斯威夫特的句法糖

import Foundationvar point = CGPoint(x: 10.0,y: 20.0)let p = withUnsafeMutablePointer(&point) {  }print(p.dynamicType) // UnsafeMutablePointer<CGPoint>
总结

以上是内存溢出为你收集整理的ios – 如何在swift中创建UnsafeMutablePointer对象全部内容,希望文章能够帮你解决ios – 如何在swift中创建UnsafeMutablePointer对象所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1022644.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存