Thursday, 25 September 2014

Best iOS interview questions on swift programming language


I started this post to all  iOS developers/beginners to prepare your self for Swift Interview questions. As its time to prepare with Swift interview questions. Swift is going to replace objective-c so we all have to prepare for best iOS interview questions on swift.

What is Swift ?

Swift is Apple's latest programming language for iOS and OS X apps that builds on the best of C and Objective-C, without the constraints of C compatibility. Swift adopts safe programming patterns and adds modern features to make programming easier, and flexible. 

Swift will replace Objective-C as the primary language in which iPhone and Macintosh applications are written.

How we declare variables in Swift ?

Constants and variables must be declared before they are used. Declare constants with the 'let' keyword and variables with the 'var' keyword.

What is difference between 'let' and 'var' declaration ?

constants are expressed with the ‘let’ keyword. So once assigned value can not be change, but assigned values using 'var' keyword can be change.

In terms of objective -c or compare with  objective -c, 'var' is  Mutable and  'let' is NonMutable.

let kMyConstant = 40
Or
let  kMyConstant: Int = 40

var myString = "This is my string."

What is Initialization ?

Initialization is the process of preparing an instance of a class, structure, or enumeration for use. This process involves setting an initial value for each stored property on that instance and performing any other setup or initialization that is required before the new instance is ready for use.
You implement this initialization process by defining initializers, which are like special methods that can be called to create a new instance of a particular type. Unlike Objective-C initializers, Swift initializers do not return a value. Their primary role is to ensure that new instances of a type are correctly initialized before they are used for the first time. 

Initializers
Initializers are called to create a new instance of a particular type. In its simplest form, an initializer is like an instance method with no parameters, written using the init keyword:
init() {
// perform some initialization here
}

In Swift How to connect UI under Swift Environment ?

UI connectivity has no change, its similar to objective-c. Xib/Storyboard under Interface builder.

1 comment: