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.

 

structure example swift programming

structure example swift programming Here’s a simple structure example in swift. We are creating three structures. One with get and set methods. Later we are initializing their instances. How get and set method works is written in code.

 

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.

 

Closures example swift – How to write ?

Closures example swift – How to write ? Closure gives the feature to write an inline function block. Here. we have taken an example of array mapping.

Notice the “!” mark in dictionary subscript. It is used because a dictionary always returns an optional value making sure the case that a key might contain… Read More »

defer swift – what is defer in swift ?

defer swift – what is defer in swift ? It’s similar to the finally{} black used in C++ and Java. That means the code in defer will run anyways no matter what.