我目前正在将我的swift文件转换为swift 3,有一个运行时异常涉及指针。代码如下:

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

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

致命错误:在展开可选值时意外找到nil
函数签名专用化)>()
到@callee\u owned(@unowned Swift.UnsafeBufferPointer)->
(@out()),参数类型:[@callee\u owned(@unowned
Swift.UnsafeBufferPointer)->()]>泛型
专业化
Swift.StaticString.withUTF8Buffer的静态字符串
((Swift.UnsafeBufferPointer)->A)->A
编辑:
getSectionChanges()的定义:
open func getSectionChanges(_ sectionChangesPtr: AutoreleasingUnsafeMutablePointer<NSArray>?, rowChanges rowChangesPtr: AutoreleasingUnsafeMutablePointer<NSArray>?, for notifications: [NSNotification], with mappings: YapDatabaseViewMappings)

请帮忙?!

最佳答案

方法定义暗示:参数autoreleasingusafemutablepointer?不接受nil NSArray对象的地址。因此,您应该使用以下代码来调用该方法:

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

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

09-25 16:47