Allreadyhome
Allreadyhome

Reputation: 1262

Core Data Int going in with correct value and coming out with wrong one - Swift

Been trying to workout the issue for a while now. I am parsing data from a API and inputing it into my core data entity attribute which is a Int.

//Visit Details
if let dateInteger = element["date"] as? Int{
    println("RESPONSE OUTSTANDING DATE: \(dateInteger)")
//OUTPUTTING AS 1435586400
    visitEntity.dateDue = NSNumber(integer:dateInteger)
}

When fetching it I am using

//Fetch Vists and related Objects
        let currentVisits = fetchedResultsController.objectAtIndexPath(indexPath) as! VisitDetails
        println("TIMESTAMP INT \(currentVisits.dateDue)")
//Outputing as -14288 

I'm pretty confused. I have tried it with various different output types but it isn't coming out with the correct value.

Upvotes: 0

Views: 268

Answers (1)

Mike Taverne
Mike Taverne

Reputation: 9352

I can repro a similar problem, though the number I am seeing is 20320 not -14288.

Check to make sure that the dateDue attribute in your data model is defined large enough to hold the largest value returned by your API.

My guess is you might have defined it as Int16 instead of Int32 or Int64.

Upvotes: 2

Related Questions