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 Build an Interactive Story App with Swift 2 Adding Sound Effects URLs for Sound Files

Paul M
Paul M
16,370 Points

What is the Difference Between all of the Different Integer Types in Swift?

I saw in the video he had something of type UIInt32. I did some research and found there is

Int16
Int32
Int64

but what is the diffrence beetween each one?

3 Answers

Shahar Rosen
Shahar Rosen
18,957 Points

I'm not completely sure but it should have to do with the base of the integer. The number represents the amount of bits used to store the integer in the system's memory, Higher number means you could represent higher integers.

For example the highest integer you can store in an Int32 would be 2,147,483,647 (or -2,147,483,647) This is a very low level basic principle of computer programming and you should look it up - http://stackoverflow.com/questions/9696660/what-is-the-difference-between-int-int16-int32-and-int64

Michael Hulet
Michael Hulet
47,912 Points

Shahar's on the right track. It just represents how many bits are used to store the number, and thus, how high the number can be. The most common types you'll ever work with, though, are just the normal Int and occasionally UInt, which is an integer that can't be negative, but can be twice as large as a normal Int.

On 64-bit platforms (iPhone 5s and higher), Int is the same as Int64, and on 32-bit platforms (iPhone 5 and earlier), Int is the same as Int32. You can read more about Swift integers in the "Integers" section on this page of The Swift Programming Language Book

Paul Maxeiner ā€”

go to here in the Apple Developer API reference, scroll down to the section on "Integers," about half way down.

having an Apple Developer account and going there to search on these topics is always a good first tool. The account is free until you want to get a Certificate to upload an App to the App store, then $99/year.

best,

ā€” faddah portland, oregon, u.s.a.