Tag Archives: swift

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 »

init method simple example swift programming

init method simple example swift programming Example below shows use of init method. It is used for initialization of the structure,class or enumeration property. In swift, we must initialise the properties before using them. So either you can do it while declaring them if they are not going to change for all instances. In case,… 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 »

willSet didSet example swift – How to use ?

willSet didSet example swift willSet and didSet are called property observers. They observe the changes in the value of a property. willSet observe what changes are made that means new value and didSet observe what change was made that is old value.

 

cannot convert return type int to return type ()->int

cannot convert return type int to return type ()->int If you are working with nested functions and you face such error while returning a function then see if you haven’t used parentheses after function name after return.