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

WKWebView NSCoding support was broken in previous versions

WebKit was introduced in iOS 8 but was released with an error which resulted in a runtime crash if the configuration was done using Interface Builder. So in Xcode 9 if your project configuration has minimum OS support less than 11.0 and you try to add WebKit using interface builder Xcode shows an error. This … Read more

Add Custom Font in iOS Application Xcode 9

Adding custom font of your choice or of your business theme, in your iOS app is quite important. Custom fonts can enrich your app and transform it from just and app to an awesome app. Adding custom font in iOS application is a step by step process. In this article we have listed all the steps and in order, we have provided enough images so that you do not lose the track

A demo project has been created in which we will add a custom font. We assume that you have the basic knowledge of creating projects creating outlets and you have a custom font file. To begin with the demo app is a simple app with a UILabel and default font.

Read more

Swift: Split a String into an array

In Objective-c we used componentsSeparatedByString NSString *stringToSplit=@”str0,str1,str2,str3,str4,str5″; NSArray *arrayFromString = [str componentsSeparatedByString:@”,”]; In swift we can split a string into array simply by calling split() method var stringToSplit = “str0,str1,str2,str3,str4,str5” let arrayFromString = stringToSplit.split(separator: “,”) Less code.. 🙂

Passing Data between View Controllers

A ViewController in an application is seldom standalone in nature. They require data from ViewControllers in front and from those behind them, this leaves us with two types of data passing Forward Data passing Backward data passing For discussing both kinds of data passing we have two ViewCotrollers ASViewController ASViewControllerB Forward data passing between ViewControllers … Read more

String length in Swift

To get the string length in swift we have two options depending on swift version Swift 3 yourString.characters.count //EXAMPLE if yourString.characters.count == 0{ //do something } 2. Swift 4 yourString.count //EXAMPLE if yourString.count == 0{ //do something }      

Swift UIColor utilities : Random Hex colour codes, Random UIColor

Simple to use swift functions which are very useful in development and testing.

1. Generating random UIColor in Swift: Function returns random UIColor each time

func randomUIColor(alpha:CGFloat!)-> UIColor
    return  UIColor(red: CGFloat.random(in: 0...1), green: CGFloat.random(in: 0...1), blue: CGFloat.random(in: 0...1), alpha: alpha)

2. Random HEX Color code in Swift 3: Function returns random 3 char Hex colour code each time.

Read more

Apple into BLE and WiFi aided indoor positioning

In WWDC 2014  session 708 Apple gave a introduction about indoor positioning. The indoor positioning is a area which cannot be covered using GPS as the signals are not expected to be accurate enough inside steal and concrete structure.So the the available signals were WiFi and beacons using BLE.

Read more

UITableView Tutorial : Creating a simple app in swift

This article has been updated for Swift 3

One of the most versatile UI elements which you come across in iOS development is UITableView.With a combination of custom cell and animation its possibilities are endless.From fancy menu to image scroll you must have found it at many places. In fact UITableView is so versatile that you can truly divide UI in two parts those which can be made using UITableView and those which cannot.I must admit in one of my lazy spur i rotated UITableView using CGAffineTransform to implement horizontal scroll.

Read more


Join group of Software Professionals