본문 바로가기
Swift

[Swift] Int vs Int32, Int64

by Sky Titan 2023. 1. 7.
728x90
 

What is the difference between Int and Int32 in Swift?

In Core Data you can store Int16, Int32, Int64 but it is different from Int. What is the reason for their existence, how do you use them?

stackoverflow.com

 

 

The Basics — The Swift Programming Language (Swift 5.7)

The Basics Swift is a new programming language for iOS, macOS, watchOS, and tvOS app development. Nonetheless, many parts of Swift will be familiar from your experience of developing in C and Objective-C. Swift provides its own versions of all fundamental

docs.swift.org

Int vs Int32, Int64

 In most cases, you don’t need to pick a specific size of integer to use in your code. Swift provides an additional integer type, Int, which has the same size as the current platform’s native word size:
On a 32-bit platform, Int is the same size as Int32.On a 64-bit platform, Int is the same size as Int64.
Unless you need to work with a specific size of integer, always use Int for integer values in your code. This aids code consistency and interoperability. Even on 32-bit platforms, Int can store any value between -2,147,483,648 and 2,147,483,647, and is large enough for many integer ranges.

 기본적으로 Int형은 32bit 플랫폼에서는 Int32와 동일하게 32bit만큼의 사이즈를 가지게 되고, 64bit 플랫폼에서는 Int64와 동일하게 64bit만큼의 사이즈를 가지게되는, 즉 현재 platform native word size를 따르게 된다.

 

 그럼에도 불구하고 명시적으로 특정한 사이즈의 Integer를 활용해야하는 경우엔 Int32, Int64와 같은 Data type을 사용하면 된다.

728x90

댓글