我有一个全球定义的array
,其中包含了ViewController
类顶部的很多表情符号/字符串。
var emojis: [[String : Any]] =
[["name": "Recently used emojis", "emojis" : []], ["name": "header2", "emojis" : ["g", "Y", "U", "g", "2", "2", "2" ,"2" ," 2" ," 2", "2" ,"2", "42", "32", "2", "32", "23", "23", "1", "1", "1", "2", "g", "2", "2", "2" ,"2" ," 2" ," 2", "2" ,"2", "42", "32", "2", "32", "23", "23", "2", "1", "2", "gk", "tT"]], ["name": "header3 and a bit more text", "emojis" : ["g", "Y", "U", "g", "2", "2", "2" ,"2" ," 2" ," 2", "2" ,"2", "42", "32", "2", "32", "23", "23", "1", "1", "1", "2", "g", "2", "2", "2" ,"2" ," 2" ," 2", "2" ,"2", "42", "32", "2", "32", "23", "23", "2", "1", "2", "gk", "tT"]]]
在viewDidLoad方法中,我填充了“数组中最近使用的表情符号,因为我需要通过NSUserDefaults
访问它。
var recentEmojiArray: Array<Any> = []
if let prefs = UserDefaults(suiteName: "com.apple.EmojiPreferences") {
if let defaults = prefs.dictionary(forKey: "EMFDefaultsKey"){
if let recents = defaults["EMFRecentsKey"] as? [String]{
recentEmojiArray.append(recents)
}
}
}
之后,我将最近使用过的emojis添加到数组中,并将重新加载我的collectionView中的数据。
emojis[0] = ["name": "Recently used emojis", "emojis": recentEmojiArray[0]]
collectionView.reloadData()
但是,每次我更改emojis
数组中的值时,我都会遇到崩溃似乎指向悬空指针的崩溃。这是最新的追踪:
(主题1)
libobjc.A.dylib`_mapStrHash:
0x10e10d756 <+0>: xorl %ecx, %ecx
0x10e10d758 <+2>: testq %rsi, %rsi
0x10e10d75b <+5>: je 0x10e10d7a3 ; <+77>
0x10e10d75d <+7>: movb (%rsi), %al
-> 0x10e10d75f <+9>: testb %al, %al
0x10e10d761 <+11>: je 0x10e10d7a3 ; <+77>
0x10e10d763 <+13>: addq $0x4, %rsi
0x10e10d767 <+17>: xorl %ecx, %ecx
0x10e10d769 <+19>: movzbl %al, %eax
0x10e10d76c <+22>: xorl %eax, %ecx
0x10e10d76e <+24>: movzbl -0x3(%rsi), %eax
0x10e10d772 <+28>: testl %eax, %eax
0x10e10d774 <+30>: je 0x10e10d7a3 ; <+77>
0x10e10d776 <+32>: shll $0x8, %eax
0x10e10d779 <+35>: xorl %eax, %ecx
0x10e10d77b <+37>: movzbl -0x2(%rsi), %eax
0x10e10d77f <+41>: testl %eax, %eax
0x10e10d781 <+43>: je 0x10e10d7a3 ; <+77>
0x10e10d783 <+45>: shll $0x10, %eax
0x10e10d786 <+48>: xorl %ecx, %eax
0x10e10d788 <+50>: movzbl -0x1(%rsi), %ecx
0x10e10d78c <+54>: testl %ecx, %ecx
0x10e10d78e <+56>: je 0x10e10d7a1 ; <+75>
0x10e10d790 <+58>: shll $0x18, %ecx
0x10e10d793 <+61>: xorl %eax, %ecx
0x10e10d795 <+63>: movb (%rsi), %al
0x10e10d797 <+65>: addq $0x4, %rsi
0x10e10d79b <+69>: testb %al, %al
0x10e10d79d <+71>: jne 0x10e10d769 ; <+19>
0x10e10d79f <+73>: jmp 0x10e10d7a3 ; <+77>
0x10e10d7a1 <+75>: movl %eax, %ecx
0x10e10d7a3 <+77>: movzwl %cx, %eax
0x10e10d7a6 <+80>: movl %ecx, %edx
0x10e10d7a8 <+82>: shrl $0x10, %edx
0x10e10d7ab <+85>: xorl %eax, %edx
0x10e10d7ad <+87>: imull $0xfff1, %edx, %eax ; imm = 0xFFF1
0x10e10d7b3 <+93>: addl %ecx, %eax
0x10e10d7b5 <+95>: retq
当我从数组中删除值时,不会发生错误。
这里发生了什么?