Swift Basic Data Types & Type Inference
5 (1)

Click to rate this post!
[Total: 1 Average: 5]

Swift is strongly typed, data should either be explicitly assigned or inferred, the main basic data types that come with swift are

TypeDescription
Charactera 16-bit Unicode character like “a” or “/”
Stringrepresents textual data like “Hello”
Floatrepresents 32-bit floating-point number
Doublerepresents 64-bit floating-point number
Boollogical value: true or false
Tuplesgroups multiple values in single value
Intinteger, a whole number
UIntunsigned integer, a whole number
Int81 byte integer
Int324 bytes integer
Int648 bytes integer
UInt81 byte unsigned integer
UInt324 bytes unsigned integer
UInt648 bytes unsigned integer


On a 32-bit device, Int has the size of Int32, on 64-bit devices, Int has the size of Int64, same goes for UInt.

Swift has a feature where it can infer the type of the data directly, for example the variable level here is infered to be an Int

var level = 12

you can explicitly determine the type directly

var level: Int = 17

Extra Tip: A CGFloat holds either 32-bits of data or 64-bits of data depending on the CPU Architecture.

Swift Variables and Constants
5 (1)

Click to rate this post!
[Total: 1 Average: 5]

Any meaningful program should contain stores to save data, swift distinguishes between constant and variable pieces of data with let and var keywords, for example, say you have a customer object, their birthdate is a constant, but their balance is a variable, if you declare data as a constant, the compiler will not allow you to have it changed later, even at compile time, this is not only for safety, but constants are generally faster to work with by the processor.

class Customer {
	let id = 22034
	let birthdate = "11/11/2011"
	var balance = 109.3
}

Constants cannot change after you run your app, they prevent accidental breakage of a value that should not change.

Swift Style Guides (a brief look)
5 (1)

Click to rate this post!
[Total: 1 Average: 5]

You most probably was working on an open source project, and must have noticed projects are usually organized and consistent 🧐, this is due to following a code style, and you must have noticed that some projects are messy, ugly and inconsistent 🤮.

There are different Swift Code Styles, one by Apple, Google, Ray Wenderlich, Linkedin and AirBNB, and others, preferring a code style over another is subjective, I recommend inspecting different styles and adopt one according to the project needs.

Developers spend time reading code, more than writing new code 😌, this alone justifies having a consistent clean coding style, this is an investment you do for yourself as a developer, and for your colleagues 😇, regular indentation, proper spelling, .. etc does not make your task take longer, in the contrary, it saves you big load of time in the future, and improves readability and maintainability.

There is an official API Design guidelines, it covers naming conventions, but is not comprehensive enough.

Another guideline can be found here, by Nikita Lazarev-Zubov, it looks like she has preservations on some guidelines too, I highly recommend going through these guidelines and inspecting yourself.