Apple iOS Swift Interview Questions
Questions Answers Views Company eMail

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

1 2145

What is Initialization ?

1 2269

In Swift How to connect UI under Swift Environment ?

1 2287

Swift defines the AnyObject type alias to represent instances of any reference type, and it’s internally defined as a protocol. Consider the following code: var array = [AnyObject]() struct Test {} array.append(Test()) This code generates a compilation error, with the following error message: Type 'Test' does not conform to protocol 'AnyObject' The failure is obvious because a struct is a value and not a reference type, and as such it doesn’t implement and cannot be cast to the AnyObject protocol. Now consider the following code: var array = [AnyObject]() array.append(1) array.append(2.0) array.append("3") array.append([4, 5, 6]) array.append([7: "7", 8: "8"]) struct Test {} array.append(Test()) The array array is filled in with values of type respectively int, double, string, array and dictionary. All of them are value types and not reference types, and in all cases no error is reported by the compiler. Why?

1 2695

Consider the following code: let op1: Int = 1 let op2: UInt = 2 let op3: Double = 3.34 var result = op1 + op2 + op3 Where is the error and why? How can it be fixed?

1 3489

Consider the following code: var defaults = NSUserDefaults.standardUserDefaults() var userPref = defaults.stringForKey("userPref")! printString(userPref) func printString(string: String) { println(string) } Where is the bug? What does this bug cause? What’s the proper way to fix it?

1 3304

The following code snippet results in a compile time error: struct IntStack { var items = [Int]() func add(x: Int) { items.append(x) // Compile time error here. } } Explain why a compile time error occurs. How can you fix it?

1 3598

In Swift enumerations, what’s the difference between raw values and associated values?

1 6996

The String struct doesn’t provide a count or length property or method to count the number of characters it contains. Instead a global countElements() function is available. When applied to strings, what’s the complexity of the countElements function: O(1) O(n) and why?

1 2374

struct Planet { var name: String var distanceFromSun: Double } let planets = [ Planet(name: "Mercury", distanceFromSun: 0.387), Planet(name: "Venus", distanceFromSun: 0.722), Planet(name: "Earth", distanceFromSun: 1.0), Planet(name: "Mars", distanceFromSun: 1.52), Planet(name: "Jupiter", distanceFromSun: 5.20), Planet(name: "Saturn", distanceFromSun: 9.58), Planet(name: "Uranus", distanceFromSun: 19.2), Planet(name: "Neptune", distanceFromSun: 30.1) ] let result1 = planets.map { $0.name } let result2 = planets.reduce(0) { $0 + $1.distanceFromSun } What are the types and values of the result1 and result2 variables? Explain why.

1 2785

Consider the following code: var array1 = [1, 2, 3, 4, 5] var array2 = array1 array2.append(6) var len = array1.count What’s the value of the len variable, and why?

1 3515

What is tuple? How to create a tuple in swift?

637

What are the two main integer types in swift?

646

What is forced unwrapping?

700

How can you prioritize the usability of the demand process?

662


Post New Apple iOS Swift Questions

Un-Answered Questions { Apple iOS Swift }

Is swift similar to python?

701


What is an attribute in swift?

674


How can we define a base class in swift?

624


What is difference between class and struct swift?

651


What is $0 and $1 in swift?

669


Which compiler is used in swift?

635


What is swift in ios?

583


How do I add a header in swift?

562


How can you make a property optional in swift?

654


What do you do when you realize that your app is prone to crashing?

643


Which is the superclass of all the view controller objects?

656


What are the features of swift programming?

656


How to pass the data between view controllers?

668


Explain the common execution states for a swift ios app (ios application lifecycle).

609


What is atomic swift?

589