gpt4 book ai didi

ios - Swift 3 - 发送可选绑定(bind)变量的指针 - iOS

转载 作者:行者123 更新时间:2023-11-28 08:25:36 25 4
gpt4 key购买 nike

我目前正在将我的 swift 文件转换为 swift 3,但存在涉及指针的运行时异常。这是代码:

var sectionChanges:NSArray? = nil
var rowChanges:NSArray? = nil

databaseView.getSectionChanges(&sectionChanges!, rowChanges: &rowChanges!, for: notifications, with: mappings)

fatal error :在展开可选值时意外发现 nil

function signature specialization ) -> () to @callee_owned (@unowned Swift.UnsafeBufferPointer) -> (@out ()), Argument Types : [@callee_owned (@unowned Swift.UnsafeBufferPointer) -> ()]> of generic specialization of Swift.StaticString.withUTF8Buffer ((Swift.UnsafeBufferPointer) -> A) -> A

编辑:getSectionChanges() 的定义:

open func getSectionChanges(_ sectionChangesPtr: AutoreleasingUnsafeMutablePointer<NSArray>?, rowChanges rowChangesPtr: AutoreleasingUnsafeMutablePointer<NSArray>?, for notifications: [NSNotification], with mappings: YapDatabaseViewMappings)

请帮忙?!

最佳答案

作为方法定义暗示:参数 AutoreleasingUnsafeMutablePointer?不会接受 nil NSArray 对象的地址。所以你应该使用下面的代码来调用该方法:

var sectionChanges = NSArray()
var rowChanges = NSArray()

databaseView.getSectionChanges(&sectionChanges, rowChanges: &rowChanges, for: notifications, with: mappings)

关于ios - Swift 3 - 发送可选绑定(bind)变量的指针 - iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40108063/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com