Structure swift language programming – struct

Structure swift language programming – struct Structure in swift is similar to C structures and also similar to class in swift. One of the most important differences between structures and classes is that structures are always copied when they are passed around in your code, but classes are passed by reference.

 

rawValue enum swift – what is rawValue ?

rawValue enum swift – what is rawValue ? It’s the value hold by name in enum. By default swift assigns enum value as zero and then incrementing by one. For accessing rawValue we can see example below:

 

willSet method swift programming – how it works ?

willSet method swift programming The code that’s written in this method is run anytime outside the initializer.

On setting up square sideLength, it will set the triangle sideLength by self. There’s another method didSet as well and that we will see in later on posts.

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()

 

Closures in swift – what are closures ?

Closures in swift Closures are block of function code that can be written without name inside another function call. Just write code within braces {}

 

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.

 

Functions syntax swift – how to write ?

Functions syntax swift func is used to declare a function and passing parameters in parentheses. -> is used for the return type.

 

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.