Swift Interview Questions And Answers

1. What is IOS Swift?

Ans. A new programming language that is developed by Apple Inc in June 2014 to create and develop the applications for mobiles and desktops. This language works with macOS, iOS, watchOS and also tvOS.

Swift supports various operating systems such as Free SD, Darwin, Linux and so on.

2. What are the advantages of using swift language?

Ans. Swift is one of the rapidly growing languages,  this language helps us to develop software’s that are incredibly fast, reliable, secure and robust. Swift is mostly used to develop the programmes for macOS, iPhone/ iPad(IOS)  

3. What are the applications of Swift language?

Ans.

  • Open-source language

  • Very easy to learn and maintain

  • Closures

  • Supported by multiple devices

  • Supports dynamic libraries

  • Optional types

4. If there is no IOS device then how can we test Apple iPhone applications?

Ans. If we don’t have iOS then we can test those applications on simulators provided by apple on the mac system

5. List the tools that are required to develop iOS application?

Ans.

  • MacMini/mac

  • Xcode

  • Apple Developer Program

  • Swift Programming Language

6. List the states of the iOS application life cycle?

Ans.

  • Not Running

  • Inactive

  • Active 

  • Background 

  • Suspend 

7. Is Swift an object-oriented programming language?

Ans. Yes, Swift is an object-oriented programming language

8. Define the term “defer”?

Ans. Defer keyword gives a block of code which executes whenever the execution is moving out from the current scope

9. What are the characteristics of a swift programming language?

Ans.

  • Efficient enums and structs

  • Optional types

  • Protocol oriented

  • Less code

  • Fewer files

  • Tuples 

  • Closures 

  • Safe by default

10. What are the data types of Swift?

Ans.

  • Int 

  • Double and Float

  • Bool 

  • String 

  • Arrays 

  • Dictionaries 

11. What is the control transform statements?

Ans.

  • Return 

  • Break 

  • Continue 

  • Fallthrough 

12. What is a swift message?

Ans. The swift message is a library within iOS which displays brief messages in the form of the status bar over the bottom or top of the screen

13. Explain about dictionaries in swift language?

Ans. It allows you to save the key-value pairs and obtain the content by giving the key. It is comparable to one of the hash tables in other some programming languages.

14. What is Enum in Swift programming language?

Ans. An enum in swift is utilised to defines a general type for a collection of related values. It permits you to operate with these values in a type-safe method in your code.

15. How to write multiple line comment in swift?

Ans. We can write multiple line comment in between this symbol /* */

16. Define what is the base class in swift?

Ans. The classes are not inherited straight of the base class in this Swift programming language. The classes determined by the developer without defining the superclass fits the base class automatically. 

17. What is a regular expression?

Ans. Regular expressions are the special string models that illustrate how a search is achieved within a string.

18. What is a Responder chain?

Ans. It is a regime of objects that get the possibility to react to the events. 

19. Explain about Functions?

Ans. It allows you to group a series collectively to accomplish a particular task. A function once generated can be over and over within the code, and in case you discover a recurrent statement within the code, then the function can be the solution to withdraw the renewal.

20. What is an adapter?

Ans. It allows the classes including incompatible interfaces to operate together and it winds itself throughout the object to present a regular interface to interact with such an object.

21. What is the memento pattern?

Ans. This pattern in iOS is applied as a member of state recovery. That is this externalized state can be reconstructed without disrupting any encapsulation. This pattern is primarily utilised for the archiving within Apple.

22. What is optional and what problem does it solve?

Ans. An optional allows a variable of any type represents a lack of value In Objective-C, the deficiency of value is accessible only in indicating types utilising the nil specific value. Value types, so an int or float, do not possess this capability.

Swift prolongs the lack of value theory to both implication and value types with optional. An optional variable can handle both value or nil, designating a lack of value.

23. Explain about generics?

Ans. Within Swift, you can utilise generics inside both functions and data types, for example, in classes, structures/enumerations.

Generics resolve the difficulty of code duplication. While you have a method that uses one type of parameter, it is general to duplicate it to provide a parameter of a distinctive type.

24. What is the swift protocol?

Ans. A protocol is a standard that determines a blueprint of methods, resources and other requirements. A class, structure or enumeration can then choose the protocol to achieve those needs.

25. Explain about init()?

Ans. Initialization is a method of making an example of an enumeration, structure or class for performance.

Initializers are also invited to design a new example of a particular type. An initializer is an example method without parameters. Utilizing the initializer, we can address the init keyword.

26. Which JSON framework is supported by iOS?

Ans. The JSON framework that is supported by iOS is SBJson.

27. Explain about closures?

Ans. If you copied the variable with a closure assigned to it and copied this variable into another variable then you can also copy a reference to the same closure and its capture list so by this we can say the closure is a reference type.

28. Describe circular reference in swift?

Ans. A circular reference occurs when a couple of instances include a strong reference respectively, creating a memory leakage because neither of the two situations will ever be deallocated. The purpose is that you cannot deallocate an instance as long as there is a sharp reference to it, though each instance holds the other vital because of its powerful reference.

29. What is PLIST?

Ans. PLIST is abbreviated as Property List. PLIST is primarily a dictionary of value and keys that can be saved in our file system using a .plist file extension. The characteristic list is utilised as a transportable and lightweight means to save a minor quantity of data, They are usually addressed in XML.

30. List three-shift pattern matching techniques?

Ans.

  • Typecasting patterns

  • Wildcard patterns

  • Optional patterns

31. What is @synthesize in Objective -C?

Ans. Getter and setter methods are created by using @synthesize in objective -C

32. What is @dynamic in objective -C?

Ans. It is used to notify the compiler whenever the getter and setters are implemented in some other place.

33. What are the steps to follow when your application is prone to crash?

Ans.

  • The first step is to determine the model and iOS version of that device

  • Collect the appropriate information to reproduce the problem

  • If possible, obtain device logs

  • Get tooling or build a unit test and start debugging once you understand the concept of the character of the problem.

34. Explain what is single-? In swift?

Ans. In swift single? Is utilised to indicate an optional value which either contains a value or nil to indicate a missing value

35. Explain what is double ?? in swift?

Ans. double ?? in swift is described nil coalescing operator that detects if optional has no value later it utilises a default value.

36. What are the steps to call objective -c code from swift?

Ans.

  • Add objective -C Implementation

  • Add bridging header 

  • Add objective -C header

  • Build your Objective -C class

37. What are the two main integer types in swift?

Ans. There are two main integer types in swift they are

  • Signed integer

  • Unsigned integer

38. What is in-out parameter?

Ans. In-out parameter allows you to modify the content of a function parameter from inside the basis of that function.

39. How can we define Ksomeconstant as an integer?

Ans. We can implicitly define Ksomeconstant as an integer

 kSomeConstant: Int = 40 

40. What is a GUARD statement?

Ans. A GUARD statement is utilised to assign the program control outside the scope while one or more provisions are not met. Applying this statement assists in withdrawing the monument of doom.