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
Emre Dokur
3,490 PointsNSNumber vs int
Hey guys,
I've been watching the Randomization video inside the "Build a simple iphone app", and a question stuck on my mind. First, here is the link to the video: http://teamtreehouse.com/library/build-a-simple-iphone-app-ios7-2/creating-a-data-collection/randomization
My question is: Why did the instructor declared the random variable as "int". A few videos before, we have seen NSNumber and used it up to this point. I know "int" does the job here, but can you please clarify when to use NSNumber and when to use "int" and why?
Thanks in advance, Emre
3 Answers
Stone Preston
42,016 PointsNSNumber basically makes those primitive types into objects. So if you need an object (or pointer) then you need to use NSNumber since some methods dont accept those primitive types as arguments, they only accept objects
As for why he declared it as int:
The arc4random_uniform function returns a "random" integer which is why the variable he assigned the return value to had to be of type int.
John W
21,558 Points(I need to type faster next time) ^ See Stone's explanation.
Emre Dokur
3,490 PointsThanks guys, It's very clear now.