我有这个功能:
func processReceivedRandomNumber(randomNumberDetails: RandomNumberDetails) {
// 1
let mutableArray = NSMutableArray(array: orderOfPlayers)
mutableArray.add(randomNumberDetails)
// 2
let sortByRandomNumber = NSSortDescriptor(key: "randomNumber", ascending: false)
let sortDescriptors = [sortByRandomNumber]
mutableArray.sort(using: sortDescriptors)
// 3
orderOfPlayers = NSArray(array: mutableArray) as! [RandomNumberDetails]
// 4
if allRandomNumbersAreReceived() {
receivedAllRandomNumbers = true
}
}
我称之为:
processReceivedRandomNumber(randomNumberDetails: RandomNumberDetails(playerId: player, randomNumber: messageRandomNumber.randomNumber))
使用的类:
class RandomNumberDetails: NSObject {
let playerId: String
let randomNumber: UInt32
init(playerId: String, randomNumber: UInt32) {
self.playerId = playerId
self.randomNumber = randomNumber
super.init()
}
func isEqual(object: AnyObject?) -> Bool {
let randomNumberDetails = object as? RandomNumberDetails
return randomNumberDetails?.playerId == self.playerId
}
}
我收到此错误消息:
此类不是密钥值编码兼容的密钥randomNumber。'
***第一次抛出调用堆栈: (0x1850ff164 0x184348528 0x1850fee2c 0x185ab2434 0x1859f8e20 0x1859f8874 0x1859f861c 0x100f97d90 0x100f9a30c 0x100f9b4a8 0x100f91c3c 0x100f91d8c 0x19ee9baa0 0x19ee9bba8 0x19eea29e0 0x19e62ab1c 0x185afb2e4 0x1850a777c 0x1850a76fc 0x1850a6f84 0x1850a4b5c 0x184fc4c58 0x186e70f84 0x18e71d5c4 0x100f658d8 0x184ae456c)
libc ++ abi.dylib:以NSException类型的未捕获异常终止 (lldb)
有什么问题?