Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Swift : Core Data Integers displaying weird values

http://stackoverflow.com/questions/31801058/swift-core-data-integer-weird-values

Just started learning Swift and have a question around Core Data. I have a very simple entity named "Score" with one attribute "points" which is of type Int16.

Here's my data model class:

class Score: NSManagedObject {
    @NSManaged var points: Int
}

Here's the code on my View Controller:

override func viewDidLoad() {
super.viewDidLoad()

let entity = NSEntityDescription.entityForName("Score", inManagedObjectContext:managedObjectContext!)
let score = Score(entity: entity!, insertIntoManagedObjectContext: managedObjectContext)

println(score.points)
}

What prints in the console is this number: -5764607523034234879

I don't understand what I'm doing wrong. I looked elsewhere and perhaps I need to do something with NSNumber, but I'm unfamiliar with that class.

Shouldn't score.points be empty right now?