R.Ham R.Ham - 1 year ago 74
Swift Question

Swift: Cannot convert of type NSNumber to expected argument type Int16

I have a CoreData entity named EntityOne and it has two attributes:
coreValue of type Int16
coreDate of type NSDate

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!)

let request = NSFetchRequest(entityName: "EntityOne")
let fetchResults = try context.executeFetchRequest(request) as! [EntityOne]

var coreDataDates = [NSDate]()
var coreDataValues = [Int16]()

for item in fetchResults {

Answer Source

Try doing this:


You should also think about safely unwrapping these before using them:

if let value = item.coreValue {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download