Swift – Functions and Closures ( Part 3 )

Functions

Methods in Swift is called as function and define by func keyword, after this keyword you should write the name of your function, parameters by their types and names in parentheses and lastly -> and the return type.

func function_name ( argument_name : argument_type , ... ) -> return type{
   //Your functions's code here..
}

 Functions can take a variable number of arguments and also return more than one value.

Lets write a function that calculates min, max, avarage and sum values of an array.Read More »

Swift Tutorial

I’ve just started to learn Swift programming language after 4 years Objective C development experience. I want to share my experience in Swift language and tell about concepts in a very brief, clean and simple way as much as I can.

Screen Shot 2016-01-23 at 14.20.05First I started to use a playground to learn by experiencing and looking exact results without compiling and running. Playgrounds are very effective to write a code without having / opening any Swift project.

Being a learner / a starter / a newbie again was a little hard. You have to put all your learnings in Objective C to another space in your mind and think as simple as you can. In my very fist swift code, I found myself in a search for “how to make category (extension) in swift?”

After learning how to define constants (let), variables (var) and how to call methods. I tried to make a image with using a color, because of I didn’t find the backgroundColor property of a UIButton, all I’ve found is backgroundImage so I think I should write a extension to UIImage for having a initialising method by color. Yes, I wrote by digging a little into codes and stack overflow. But it takes some time, so I decide to learn in very beginning of Swift language and lead the way for developers like me (know Objective C very deeply and need to start learning Swift in a very clean, easy and fast way.)

This way please!

Part 1 – Define variables, constants and simple object types – Swift Hello World!
Part 2 – Use if, switch, for, for-in, while, repeat-while statements – Control Flows
Part 3 – Functions & Closures – How to call and define them
Part 4 – Objects & Classes – get, set, willSet and didSet methods of Properties
Part 5 – Enumerations & Structures – enum & struct in Swift

…To be continued!…