iOS崩溃堆栈跟踪毫无意义
我已经获得并设法为我的iOS应用程序编写了一份崩溃报告。然而,看着堆栈跟踪,我似乎无法理解它iOS崩溃堆栈跟踪毫无意义,ios,swift3,crash-reports,Ios,Swift3,Crash Reports,我已经获得并设法为我的iOS应用程序编写了一份崩溃报告。然而,看着堆栈跟踪,我似乎无法理解它 Thread 0 Crashed: 0 libswiftCore.dylib 0x00000001005d330c specialized _assertionFailure(StaticString, String, file : StaticString, line : UInt, flags : UInt32) -> Never (__hidden#17
Thread 0 Crashed:
0 libswiftCore.dylib 0x00000001005d330c specialized _assertionFailure(StaticString, String, file : StaticString, line : UInt, flags : UInt32) -> Never (__hidden#17347_:134)
1 libswiftCore.dylib 0x00000001004d7d2c Error<A where ...>._code.getter (__hidden#18979_:221)
2 libswiftCore.dylib 0x00000001004d7bf4 swift_errorInMain + 0
3 MyAppName 0x00000001000c2190 specialized PersonRepository.hydrate(Row) -> Person (PersonRepository.swift:0)
4 MyAppName 0x00000001000fbebc specialized Database.checkSchemaVersion(connection : Connection) -> () (Database.swift:0)
5 MyAppName 0x00000001000fc254 _TTSf4d_g__TZFC6MyAppName8DatabaseP33_909B711B8156620EE1EFE30EC21C4C0C11getInstancefT_S0_ (Database.swift:0)
6 MyAppName 0x00000001000fade8 static Database.getInstance() -> Database (Database.swift:0)
7 MyAppName 0x00000001000a7a6c TaskRepository.init() -> TaskRepository (TaskRepository.swift:38)
(......)
你知道堆栈跟踪(不是很stacky,嗯?)是什么意思吗?或者它是如何到达这种情况的?如果事情真的以这样的方式发展,难怪它会崩溃
更新
虽然我相信堆栈跟踪表明在数据库.checkSchemaVersion(connection:connection)->()
中的某个地方有一个对PersonRepository.hydrate(Row)->Person
的直接调用,而且这个添加是无关的,下面是PersonRepository
private init()
{
db = Database.getConnection()
table = Table("persons")
pictureRepository = PictureRepository.getInstance()
try! db.run(table.create(ifNotExists: true) {
t in
t.column(id, primaryKey: true)
t.column(name)
t.column(email)
t.column(phone)
t.column(company)
t.column(pictureId)
})
}
public func updateSchema(from: Int64, to: Int64)
{
if from < 2016121201 {
try! db.run(table.addColumn(active, defaultValue: 1))
}
}
static func getInstance() -> PersonRepository
{
if (instance == nil) {
instance = PersonRepository()
}
return instance!
}
private init()
{
db=Database.getConnection()
表=表(“人员”)
pictureRepository=pictureRepository.getInstance()
try!db.run(table.create)(ifNotExists:true){
不在
t、 列(id,primaryKey:true)
t、 列(名称)
t、 专栏(电子邮件)
t、 专栏(电话)
t、 专栏(公司)
t、 列(图片ID)
})
}
public func updateSchema(从:Int64到:Int64)
{
如果从<2016121201开始{
try!db.run(table.addColumn(活动,默认值:1))
}
}
静态func getInstance()->PersonRepository
{
if(实例==nil){
instance=PersonRepository()
}
返回实例!
}
一个提示-避免代码>尽可能多。特别是使用处理异常时,请尝试。应该有一个很好的理由,为什么东西可以扔,我相信这就是你崩溃的原因
堆栈跟踪可能并不完全明显,因为编译器可以内联/优化某些方法调用,以用于发布版本。在您的情况下,可能是这样发生的:
checkSchemaVersion(连接:连接)
PersonRepository.getInstance()
PersonRepository.init()
试试看!db.run()
抛出异常是因为数据库中发生可疑事件
如果你不能重现崩溃,我的建议是重写这段代码,不要强行展开,并思考万一出现问题该怎么办。一种解决方案是使用故障初始化器并处理上游可能的nil
值,即
private init?()
{
db = Database.getConnection()
table = Table("persons")
pictureRepository = PictureRepository.getInstance()
do {
try db.run(table.create(ifNotExists: true) {
t in
t.column(id, primaryKey: true)
t.column(name)
t.column(email)
t.column(phone)
t.column(company)
t.column(pictureId)
})
} catch {
return nil
}
}
看起来这个崩溃日志被剥离了。你能把PersonRepository的代码也贴出来吗。看起来它将进入'PersonRepository.getInstance().updateSchema(from:schemaVersion,to:build)`line@dRAGONAIR-我已经添加了该类的一个部分,但是我觉得它不相关。从堆栈跟踪可以看出,有一个从数据库.checkSchemaVersion(connection:connection)
到PersonRepository.hydrome(Row)
的直接调用,但是没有这样的调用。如果不是直接的,那么这两者之间应该有一个中间层次。这就是调用堆栈的工作原理,不是吗?谢谢,关于try代码>。我已经通过其他方法解决了这个错误-结果是我在TaskRepository
上的init()
和updateSchema()
中定义了一个新的列(因此它甚至不是这个存储库),它对从以前版本升级的应用程序很有效,但它会因为try>而崩溃代码>新安装应用程序时。至于解释堆栈跟踪中从级别4跳到级别3的主要任务,它仍然没有意义,因为hydrate()
方法仅用于从DB加载的数据,在我的应用程序中没有初始化代码这样做。
private init?()
{
db = Database.getConnection()
table = Table("persons")
pictureRepository = PictureRepository.getInstance()
do {
try db.run(table.create(ifNotExists: true) {
t in
t.column(id, primaryKey: true)
t.column(name)
t.column(email)
t.column(phone)
t.column(company)
t.column(pictureId)
})
} catch {
return nil
}
}