我目前正在将swift文件转换为swift 3,并且存在涉及指针的运行时异常。这是代码:
var sectionChanges:NSArray? = nil
var rowChanges:NSArray? = nil
databaseView.getSectionChanges(§ionChanges!, rowChanges: &rowChanges!, for: notifications, with: mappings)
致命错误:在解包可选值时意外发现nil
功能签名专业化) - > () @callee_owned(@unowned Swift.UnsafeBufferPointer) - > (@out()),参数类型:[@callee_owned(@ unowned Swift.UnsafeBufferPointer) - > ()]>通用的 专业化 Swift.StaticString.withUTF8Buffer ((Swift.UnsafeBufferPointer) - > A) - >甲
编辑: getSectionChanges()的定义:
open func getSectionChanges(_ sectionChangesPtr: AutoreleasingUnsafeMutablePointer<NSArray>?, rowChanges rowChangesPtr: AutoreleasingUnsafeMutablePointer<NSArray>?, for notifications: [NSNotification], with mappings: YapDatabaseViewMappings)
请帮帮忙?!
答案 0 :(得分:0)
方法定义暗示:参数AutoreleasingUnsafeMutablePointer?不接受nil NSArray对象的地址。因此,您应该使用以下代码来调用该方法:
var sectionChanges = NSArray()
var rowChanges = NSArray()
databaseView.getSectionChanges(§ionChanges, rowChanges: &rowChanges, for: notifications, with: mappings)
答案 1 :(得分:0)
将可选变量初始化为nil以外的其他变量似乎有所帮助。我自己回答这个问题,以防它对其他人有用。
var sectionChanges:NSArray? = NSArray()
var rowChanges:NSArray? = NSArray()
databaseView.getSectionChanges(&(sectionChanges)!, rowChanges: &(rowChanges)!, for: notifications, with: mappings)