iOS


Round vs Floor vs Ceil : Swift
Rounding up to the nearest Integer value functionality is something required a lot of times. Swift has a few inbuilt functions which can do the rounding up for us but they are a bit confusing. To decide when to use what, we need to understand which rounding function rounds up in which direction. read more
21 Jun 2022
Safe calls(?.) vs Nil checks(!.) in Swift
In Swift, the type system distinguishes between references that can hold nil (nil references) and those that can not (non-nil references). For example, a normal property can’t hold a nil value and will show a compile error. read more
18 Jun 2022
Default vs Optional vs Explicit Non-nil Variables: Swift
In Swift, we can differentiate the variables into three different categories based on their possible values. The variable can be of default type, optional type or an explicit non-nil type. read more
17 Jun 2022
Question Mark (? vs ?. vs ?? vs ? :) in Swift
In Swift, the question mark works differently in different situations or when clubbed with some other keywords. It sometimes denotes the variable type as optional or sometimes being used for optional chaining. read more
16 Jun 2022
Double vs Float : Swift
Swift has two data types (Double and Float) to hold the decimal values. Both of them hold the same decimal type values but have some differences. The basic difference is around the size of memory they both use based on which their precision varies. read more
10 Apr 2022
Custom Object in UserDefaults : Swift (Github Gist)
UserDefaults provides us with direct functions for storing primitive data types like Int, Double, Bool, and String. But for custom data types, there is no direct way to store them in UserDefaults. But there is a workaround with which we can store the custom object to UserDefaults. read more
09 Apr 2022
Custom Object in UserDefaults : Swift
UserDefaults provides us with direct functions for storing primitive data types like Int, Double, Bool, and String. But for custom data types, there is no direct way to store them in UserDefaults. But there is a workaround with which we can store the custom object to UserDefaults. read more
09 Apr 2022
UserDefaults in Swift
A small set of data is required to be stored and accessed very frequently and need to be persisted across sessions or app launches. One way of keeping them is using a local database like core data in an iOS app. But core data is helpful in the case of tables and queries. There is another way to store a small set of data, UserDefaults. read more
24 Mar 2022
UISwitch Value Change Listener : Swift (Github Gist)
Adding an editing event to a UISwitch is something that is required most of the time. For views like UISwitch, we can connect an IBAction with the event type as value changed and get a callback for the value changed. read more
20 Mar 2022
UISwitch Value Change Listener : Swift
Adding an editing event to a UISwitch is something that is required most of the time. For views like UISwitch, we can connect an IBAction with the event type as value changed and get a callback for the value changed. read more
20 Mar 2022
UIDatePicker Date Change Listener : Swift (Github Gist)
Adding an editing event to a UIDatePicker is something that is required most of the time. For views like UIDatePicker, we can connect an IBAction with the event type as value changed and get a callback for the value changed. read more
09 Mar 2022
UIDatePicker Date Change Listener : Swift
Adding an editing event to a UIDatePicker is something that is required most of the time. For views like UIDatePicker, we can connect an IBAction with the event type as value changed and get a callback for the value changed. read more
09 Mar 2022
UITextField Text Listener : Swift (Github Gist)
Adding an editing event to a UITextField is something that is required most of the time. For views like UITextField, we can connect an IBAction with the event type as editing did end or value changed and get a callback for editing finished or value changed. read more
08 Mar 2022
UITextField Text Listener : Swift
Adding an editing event to a UITextField is something that is required most of the time. For views like UITextField, we can connect an IBAction with the event type as editing did end or value changed and get a callback for editing finished or value changed. read more
08 Mar 2022
Switch Statement in Swift
The switch statement in Swift is used to execute a particular block of code based on multiple conditions. A switch statement is useful for more than one condition. For one or two conditions, if-else is a better option but for conditions more than that, a switch statement is a better option. read more
27 Feb 2022
Swift Range Operators
Range Operator in Swift is a basic operator that is used to operate over a range. There are multiple types of range operators where we can include or exclude the upper range. Or we can start the range with some value or can end before some max value. read more
05 Oct 2021
For-in vs For-each in Swift
For-in and for-each are different variants of for loops in swift which are used to iterate over a range, set or dictionary. Both provide the same functionality but has a few limitations or differences when it comes to conditional access. read more
26 Sep 2021
Swift ‘For’ loop
For loops are used by every developer regularly. There is for-in as well as a for-each loop in Swift which has a bit different syntaxes. Both of them are used to iterate over a range, array, set or dictionary but have a bit different syntaxes. read more
25 Sep 2021
Computed Property in Swift
Object creation is a heavy process. When we create a class object, all the public and private properties of that class are initialised inside the constructor. Every variable inside a class initialisation requires a certain amount of time to allocate the memory on the heap and hold its reference on the stack. read more
16 Sep 2021
lazy Property in Swift
Object creation is a heavy process. When we create a class object, all the public and private properties of that class are initialised inside the constructor. Every variable inside a class initialisation requires a certain amount of time to allocate the memory on the heap and hold its reference on the stack. read more
05 Sep 2021
Tuple in Swift
It is a very common use case where we want to return two values from a method, can be either of same data type or can be of different data types. What usually we do there is either create some local variables or we create a struct with just two variables and return that struct object from the method. read more
21 May 2021
if vs if let vs guard let in Swift
if let and guard let are two conditional operators or condition checker which make our life super easy. Other languages have only if as condition checker but swift provides if let as well as guard let also which are operationally same but a bit different in functionality. read more
16 Apr 2021
UIView ClickListener : Swift (Github Gist)
Adding a click event to a UIView is something which is required most of the times. For views like UIButton, we can simply connect an IBAction with the event type and detect the click events but sometimes we need it for Lable or even other views. read more
14 Dec 2020
UIView ClickListener : Swift
Adding a click event to a UIView is something that is required most of the time. For views like UIButton, we can connect an IBAction with the event type and detect the click events but sometimes we need it for Lable or even other views. read more
14 Dec 2020
‘mutating’ in Swift
As we all know, Classes are reference type whereas Structures and Enumerations are of a value type in swift. What does that mean is that a class object shares a single instance of the object and passes the same reference if passed to any function or new object whereas the value type is the one which creates a copy of it and passes only the value. read more
29 Mar 2019
‘inout’ in Swift
Recently, while working with swift I came up with a use case where I need to modify the variable passed as an argument to a function. Eventually, all the variables passed to a function are of an immutable type which cannot be changed which is similar to a let variable. read more
01 Mar 2019