Camera and UIImagePickerController to take photos with swift

You can easily integrate camera functionality in your application using UIImagePickerController which is built-in UIKit. It requires very few steps to do so. I am providing the basic steps below Make your viewcontroller calss conform to UIImagePickerControllerDelegate and UINavigationControllerDelegate Add extention to your viewcontroller Your code is almost done. Now add some button or function … Read more

SSL Pinning for preventing Man in Middle Attack

Communicating with a server gives an entirely new dimension to an application and can do a huge amount of value addition for both client and business. But communication with server also comes with its share of risks. A insecure connection is really a bad idea but a poorly implemented https connection is even worse. In … Read more

Swift Defer Statement explained

When you want to ensure that a code block is executed just before control exits the scope, Swift Defer Statement comes to your rescue. Sometimes a function is required to have multiple conditional exit point and covering those exit points without swift defer statement can lead to code duplication or it might just not be possible to … Read more

Swift nonmutating setters. an Oxymoron?

While going through Xcode 10.1 release notes I stumbled upon a very unfamiliar term “nonmutating setters”. Inquisitiveness had the best of me and I spent time reading about it and implementing examples. Here is the jest for you nonmutable setters cannot be used within Classes or protocol bound classes nonmutable setters do not mutate instance nonmutable … Read more

Using Codable with object under single root key

While using codable we come across situations when our object keys are not at the root level //Final code /* JSON data { “dog”: { “id”: 1, “task”: “bow wow” } }*/ struct Dog: Codable { let id: Int let task: String } let decoder = JSONDecoder() let userDictionary = try decoder.decode([String: Dog].self, from: jsonData) let … Read more

Using PromiseKit and Alamofire For Clean API Layer

Promise kit and Alamofire when used together create a very powerful and flexible API Layer Every App interacting with web services contains an API layer which separates API handling from the rest of the application logic. Usually, the API layer is implemented using delegates or escaping closures. Escaping closures and delegates are neat but we can achieve … Read more

Parsing JSON into Swift Objects directly

Parsing JSON data in into swift objects have become super easy with Swift 4 JSONDecoder.Given below is a simple example which hits a Api and parses the JSON data directly to student object.We are assuming that we have a JSON response which has same keys as names of properties. import UIKit struct Student:Decodable{// property name should be … Read more

Swift Interview Questions and Answers

This article is meant to be a guide. Target is to evolve it to a exhaustive list of swift questions and answers with your support. Given below are few of the most common questions asked in swift interview straight from swift docs, which according to me is a must read for any one trying to develop some skills in swift.Questions are added on last page.

Important swift questions you should know

Question 1.  How to declare constant in swift?

Answer: Constant are declared using let keyword and once set, attempting to change a constant value results in compile time error

let welcome = "Welcome Buddy!!!"

Question 2. Can we use Swift reserve keywords as variable or constant name? How?

Answer 2. Yes we can, we need to surround the reserve keyword in “`” (backticks)

var `protocol`:String = "Protocol is reserved"

Question 3. What are Type Aliases ? Why they are used?

Answer 3. Type Aliases are used to give alternative name for an existing type.They come in handy when we want to give a existing type a name which is more clear in applications context.

typealias PriorityLevel = UInt16

let a = PriorityLevel.min  // which is same as UInt16.min


Join group of Software Professionals