[英]Swift: Cannot convert of type NSNumber to expected argument type Int16
I have a CoreData entity named EntityOne
and it has two attributes: 我有一个名为
EntityOne
的CoreData实体,它具有两个属性:
coreValue
of type Int16
类型
Int16
coreValue
coreDate
of type NSDate
NSDate
类型的coreDate
When I try to access the core data entries from a fetch request and append the values to individual arrays the error appears for the line: coreDataValues.append(item.coreValue!)
当我尝试从提取请求访问核心数据条目并将值附加到单个数组时,该行出现错误:
coreDataValues.append(item.coreValue!)
let request = NSFetchRequest(entityName: "EntityOne")
let fetchResults = try context.executeFetchRequest(request) as! [EntityOne]
var coreDataDates = [NSDate]()
var coreDataValues = [Int16]()
for item in fetchResults {
coreDataDates.append(item.coreDate!)
coreDataValues.append(item.coreValue!)
}
Try doing this: 尝试这样做:
item.coreValue!.shortValue
You should also think about safely unwrapping these before using them: 您还应该在使用它们之前考虑安全地展开它们:
if let value = item.coreValue {
coreDataValues.append(value.shortValue)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.