Latest iOS Interview Questions & Answers 2018 - Swift 4 Tutorials W3Schools

Hot

Post Top Ad

22 Oct 2017

Latest iOS Interview Questions & Answers 2018


Top 15 2017 2018 Swift Interview Questions & Answers pdf,10 Basic Swift Interview Questions to Practice with,25 ios interview questions and answers for junior developers,ios developer interview questions for experienced,swift 3.0 interview questions,swift technical questions,advanced swift interview questions,swift 4 interview questions

Question 1:

class Person {
    var name: String
    var age: Int
    init(name: String, age: Int) {
        self.name = name
        self.age = age
    }
}

let person1 = Person(name: "John", age: 26)
var person2 = person1
person2.name = "Mike"

What's the value of person1.name and person2.name Would this be any different if Person was a class? Why?

Answer:

Both person1.name and person2.name are Mike.

Classes in Swift are reference types, and they are copied by reference rather than value. The following line creates a copy of person1 and assigns it to person2:

var person2 = person1

From this line on, any change to person1 will reflected in person2.

If Person were a structure, person1.name will be John, whereas person2.name will be Mike.
Structures in Swift are value types. Any change to a property of person1 would not be reflected into person2 and vice versa.

Question 2:

What is an optional in Swift and How it helps?

Answer:

An optional is used to let a variable of any type represent the lack of value. In Objective-C, the absence of value is available in reference types only, and it uses the nil special value. Value types, such as int or float, do not have such ability.

Swift extends the lack of value concept to both reference and value types with optionals. An optional variable can hold either a value or nil any time.

Question 3:

What is the difference between let and var in Swift?

Answer:

let kConstant = 10
var stringVariable : String

Here, we used the : string to explicitly declare that stringVariable will hold a string. In practice, it's rarely necessary — especially if the variable is given an initial value — as Swift will infer the type for you. It is a compile-time error trying to use a variable declared as a constant through let and later modifying that variable.

Question 4:

What is Completion Handler?

Answer:

Completion handlers are super convenient when our app is making an API call, and we need to do something when that task is done, like updating the UI to show the data from the API call. We’ll see completion handlers in Apple’s APIs like dataTaskWithRequest and they can be pretty handy in your own code.

The completion handler takes a chunk of code with 3 arguments:(NSData?, NSURLResponse?, NSError?) that returns nothing: Void. It’s a closure.

The completion handlers have to marked @escaping since they are executed some point after the enclosing function has been executed.

Question 5:

What is Singleton Pattern ?

Answer:

The Singleton design pattern ensures that only one instance exists for a given class and that there’s a global access point to that instance. It usually uses lazy loading to create the single instance when it’s needed the first time.

Question 6:

Closures  - value or reference types?

Answer:

Closures are reference types. If a closure is assigned to a variable and the variable is copied into another variable, a reference to the same closure and its capture list is also copied.

Question 7:

What are SQLite limits ?

Answer:

We need to define the relations between the tables. Define the schema of all the tables.

We have to manually write queries to fetch data.

We need to query results and then map those to models.

Queries are very fast.

Question 8:

What is CoreData ?

Answer:

Core data is an object graph manager which also has the ability to persist object graphs to the persistent store on a disk. An object graph is like a map of all the different model objects in a typical model view controller iOS application.

Question 9:

What are the execution states in iOS app?

Answer:

Not Running: The app is completely switched off, no code is being executed.

Inactive: The app is running in the foreground without receiving any events.

Active: The app is running in the foreground and receiving events.

Background: The app is executing code in the background.

Suspended: The app is in the background but is not executing any code.

Question 10:

What is AutoLayout?

Answer:

AutoLayout provides a flexible and powerful layout system that describes how views and the UI controls calculates the size and position in the hierarchy.

Auto Layout dynamically calculates the size and position of all the views in your view hierarchy, based on constraints placed on those views

2 comments:

  1. This is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article.
    apple ios training institutes in Hyderabad
    ios app development in hyderabad

    ReplyDelete
  2. Thanks for Sharing this Valuable Information i like this i Can Share this with My Friend Circle.
    iOS Interview Questions and Answers

    ReplyDelete

Post Top Ad