Float: A number without a fixed number of digits before and after the decimal point
Floating Point Operations: Operations that are performed on Float types
Integer: A number that has no fractional part, that is no digits after the decimal point
Java: A general-purpose programming language, designed by Sun Microsystems. Intended to allow developers to write once, run everywhere
Primitive types: The most basic data types avaliable in the Java programming language which are boolean, byte, char, short, int, long, float and double
Value: The something that would be stored in a variable
Value types: Where a value is stored as the actual value of the item
This is Swift
In other languages (and we are going to use
Java as a proxy for “other languages” here) there are basic types (
Primitive types) that are embedded in the language as the basic building blocks (for example
Swift does not have
Primitive types in this way, since an
Integer defined in Swift as Int. Now this Int type is declared by Apple as being a type which is simply a
struct in their documentation:
Integer operations are important (as are
Float) in that they relate to specialised operations in the CPU (
Integer operations typically take up one clock cycle, and although
Floating Point Operations are generally slower they generally use a Floating Point Unit to make they faster than other operations).
So how does Swift take advantage of these rather special features of the CPU if they are functionally the same as user-defined types?
The answer? That’s below.
Swift’s Standard Libarary
Those rather nice people who have been developing the Swift language have helped us out here. Within the Standard Library for Swift they have produced what they call Fundamental data types, which include Int, Double and String.
When we use the Standard Library, the functions (in the form of libraries) we use are integrated into the latest release of Swift — saving space in your ultimate app download.
If that’s not awesome, I don’t know what is!
Even better you can explore the Standard Library through a repo — https://github.com/apple/swift .
In this article we have explored Fundamental data types, the Standard Library and even referenced how you can explore the Standard Library. These are the type of tools that can help you become a better programmer.
I’d certainly urge you to do that…
The Twitter contact:
Any questions? You can get in touch with me here