如何解决线程 1:EXC_BAD_ACCESS代码=1,地址=0x879bb6700CoreData
我正在使用 CoreData 在另一个 ViewController 中用一组数据预填充 TableView(我有 Right Detail 单元格类型)。当我实际转到 TableView 时,它崩溃并给我错误“线程 1:EXC_BAD_ACCESS (code=1,address=0x879bb6700)”。
override func tableView(_ tableView: UITableView,cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Subcell",for: indexPath)
let mSub = self.mSubs![indexPath.row]
cell.textLabel?.text = mSub.newWord?.lowercased()
cell.detailTextLabel?.text = mSub.oldWord?.lowercased()
return cell
}
真正让我感到困惑的是,只有在我预先填充 newWord 数据时才会发生错误。 oldWord 数据永远不会崩溃(即使我将 oldWord 设置为保存用于调试的 newWord 数据,反之亦然)。这是我预填充数据的地方:
let launchedBefore = UserDefaults.standard.bool(forKey: "launchedBefore")
if launchedBefore {
print("Not first launch.")
} else {
print("First launch,setting UserDefault.")
UserDefaults.standard.set(true,forKey: "launchedBefore")
let ogOldWords = ["equals","plus","minus","subtracted by","negative","times","x","multiplied by","over","divided by"," squared","squared","square root of ","square root ","cube root of "," cubed","cubed"," to the ","to the ","open parentheses","close parentheses","zero","one","two","three","four","five","six","sax","sacks","seven","eight","nine","why","ask","eggs","equal","for","too","to","/","d1"]
let ogNewWords = ["=","+","-","⋅","^2","√","∛","^3","^","( "," )","0","1","2","3","4","5","6","7","8","9","Y","X","=","done"]
for i in 0..<ogOldWords.count {
let mSubO = MathSubs(context: globalVariables.context)
mSubO.newWord = ogNewWords[i]
mSubO.oldWord = ogOldWords[i]
}
do {
try globalVariables.context.save()
}
catch {
print("Could not save data")
}
}
编辑: 我有时会遇到的另一个错误是“Thread 1:”-[CALayer copyWithZone:]: unrecognized selector sent to instance 0x6000029f72a0""
编辑 2: 在处理应用的另一部分(在原始 ViewController 中)时,我再次遇到 newWord 相同的错误。
do {
mSubs = try globalVariables.context.fetch(MathSubs.fetchRequest())
for i in 0..<mSubs!.count {
mainString = mainString.replacingOccurrences(of: mSubs![i].oldWord ?? "",with: mSubs![i].newWord ?? "",options: .literal,range: mainString.startIndex..<mainString.endindex)
}
}
catch {
print("Could not fetch data")
}
应用在 newWord 而不是 oldWord 上崩溃。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。