Tag Archives: xcode

failable initialiser swift simple example

failable initialiser swift simple example In swift, Failable initialisers are used with structure,class and enumeration. When it is not sure that a property within class or structure or enumeration will be initialised then failable initialisers are used. For this, we write initialiser with init? syntax and if initialisation succeeds then value is assigned or else… Read More »

designated convenience automatic initialiser swift

designated convenience automatic initialiser swift  Example code below demonstrates the concept of all of these initialisers in swift in a simple way. We have three classes here. One is the base class, Two is its subclass and Three is subclass of Two. Example code – designated convenience automatic initialiser swift 

How these initializers work is… Read More »

mutating method swift simple example – how to write ?

mutating method swift simple example – how to write ? Structure and enumeration are value type in swift. That means an instance method can not change its properties. For example a method within structure cannot change any variable defined within structure. To do so you need a method that is mutating – means changing the… Read More »

self keyword swift simple example – what is use ?

Use of self keyword swift simple example One of the use of “self” keyword in swift is when you want refer a property within structure, class or enum. We can understand by the following example:

when we call function and within its definition if there’s written x+2 then it will refer to the x… Read More »

Initializers swift programming

Initializers swift programming A member inside the class has to be initialized in swift. If not then it will produce an error. It can be done using init() function. Assign values to members when object is created and use deinitializer to perform clean up using deinit()


Variable argument functions swift

Variable argument functions swift We write the function in the similar way, just we need to take variable number of arguments runtime then we write function in the following way with argument list ending with three dots.


For-in loop in swift

For-in loop in swift You use for–in to iterate over items in a dictionary by providing a pair of names to use for each key-value pair. Dictionaries are an unordered collection, so their keys and values are iterated over in an arbitrary order.