[valueForUndefinedKey:]:此类与键约会日期的键值编码不兼容. -迅速 [英] [ valueForUndefinedKey:]: this class is not key value coding-compliant for the key appointmentDate.' - swift

查看:101
本文介绍了[valueForUndefinedKey:]:此类与键约会日期的键值编码不兼容. -迅速的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对对象数组进行排序是我对对象数组进行排序的功能

i want to sort an array of object below is my function to sort the array of object

    class func Fn_SortByParameter(arrayToSort:NSMutableArray,paramName:NSString!, isAscending:Bool!){
    var sortDescriptor:NSSortDescriptor = NSSortDescriptor(key: paramName, ascending: isAscending, selector: Selector("localizedCompare:"))
    var sortDescriptors:NSArray = NSArray(object: sortDescriptor)
    var sortedArray:NSArray = arrayToSort.sortedArrayUsingDescriptors(sortDescriptors)
    arrayToSort.removeAllObjects()
    arrayToSort.addObjectsFromArray(sortedArray)
}

AND

class func Fn_SortByParameter(arrayToSort:NSMutableArray,paramName:NSString!, isAscending:Bool!){
    var sortDescriptor:NSSortDescriptor = NSSortDescriptor(key: paramName, ascending: isAscending)
    var sortDescriptors:NSArray = NSArray(object: sortDescriptor)
    var sortedArray:NSArray = arrayToSort.sortedArrayUsingDescriptors(sortDescriptors)
    arrayToSort.removeAllObjects()
    arrayToSort.addObjectsFromArray(sortedArray)
}

数组包含以下类的对象

class Appointment: NSObject {

     var id:Double!
      var status:NSString!
      var clinic:Clinic!
      var medicalCase:MedicalCase!
      var patient:Patient!
      var appointmentDate:Double! // Unix timestamp
      var reasonForVisit:NSString!
      var cancellationReason:NSString!
      var visit:Visit!
    }

当我尝试排序时,它崩溃并显示以下错误

When i am trying to sort it is crashing with below error

[valueForUndefinedKey:]:此类与键约会日期的键值编码不兼容.'

[ valueForUndefinedKey:]: this class is not key value coding-compliant for the key appointmentDate.'

函数调用进行排序

Fn_SortByParameter(allAppointments.aaData, paramName: "appointmentDate", isAscending: true)

推荐答案

您遇到的问题是,像Double!这样的可选值类型没有暴露给Objective-C运行时,也不可用于键值编码

The problem you're running into is that optional value types like Double! are not exposed to the objective-c runtime and not available for key-value coding.

您可以将其设置为非可选:var appointmentDate:Double,使用NSNumber对象:var appointmentDate:NSNumber!,或使用Swift数组和内置的sorted函数.

You can make it non-optional: var appointmentDate:Double, use an NSNumber object: var appointmentDate:NSNumber!, or use a Swift array and the built-in sorted function.

这篇关于[valueForUndefinedKey:]:此类与键约会日期的键值编码不兼容. -迅速的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆