Make your Swift code expressive: addition operator use cases

I like reading short and expressive code. Because developer spends more time reading code than writing, expressiveness often is obligatory. Unless shortness does not obscure the intent, I favor concise expressions over longer ones. For example: Try in Swift sandbox import Foundation let greeting = "Hello, " let who = "World" let message1 = greeting + who let message2 = greeting.appending(who) print(message1) // => "Hello, World" print(message2) // =>… Continue reading

How to use correctly 'self' keyword in Swift

In Swift self is a special property of an instance that holds the instance itself. Most of the times self appears in an initializer or method of a class, structure or enumeration. The motto favor clarity over brevity is a valuable strategy to follow. It applies efficiently in most of the cases, and helps to increase the code readability, but... affects code shortness. Applying this… Continue reading

Mastering Swift: tips about array and dictionary literals

Imagine you have a bunch of delicious candies 🍬, about 20-30 items. Normally a person can eat about 2 or 3 candies per day. To deal easier with a lot of candies, it makes sense to keep them in a single place. And reasonable this place is a plastic bag or a small box, instead of keeping them spread around and messy on the table.… Continue reading

Useful details about underscore keyword in Swift

Swift is known for its ability to help creating readable and self explanatory code. Such practice is efficient, because writing meaningful code has a big impact on understanding: and as result on productivity. The language offers useful syntax to improve the readability using argument labels, or to access a tuple or structure component. For instance the following function returns a tuple that contains the minimum… Continue reading

Coding like Shakespeare: practical function naming conventions

What a piece of work is a man! How noble in reason, how infinite in faculty! Hamlet, William Shakespeare Code is prose. Clear and meaningful prose is easy to read and follow. Everyone enjoys reading such prose. The same quality should apply to source code. The way developer express his thoughts through a programming language is important. Writing code is communication: with your teammates and… Continue reading

Mastering Swift: essential details about strings

String type is an important component of any programming language. The most useful information that user reads from the window of an iOS application is pure text. To reach a higher number of users, the iOS application must be internationalised and support a lot of modern languages. The Unicode standard solves this problem, but creates additional complexity when working with strings. On one hand, the… Continue reading

Useful tips for migrating to Swift 3.0

Not long ago the 3.0 version of Swift language was released. The new version is available in Xcode 8, or you can download the compiler directly from swift.org. The new version has a lot of improvements in terms of code readability, function invocation consistency, better naming conventions and the removal of some C-style elements. In terms of readability, the NS prefix is dropped… Continue reading