Skip to main content

15 Best Swift Interview Questions and Answers

What Is Swift Programming?
Swift is a powerful, open-source, safe, multi-paradigm and compiled programming language designed and developed by Chris Lattner, Apple Inc.

It is a safe, fast and interactive programming language for iOS, macOS, watchOS, tvOS and Linux.
Swift took language ideas from Objective-C, C#, Ruby, Python, Rust, Haskell, CLU and so on.
Swift Programming offers better type safety, security and performance.

Some Programming Patterns -
ü  Swift variables are always initialized before use.
ü  Swift array indices are checked for out-of-bounds errors.
ü  Swift is an alternative to the Objective-C language.
ü  Memory is managed automatically.
ü  Error handling allows controlled recovery from unexpected failures.
Swift Version History -
Mid 2010 - Development begins
Jun 2014 - Apple announces Swift at WWDC 2014
Sep 2014 - Apple releases Swift 1.0
Oct 2014 - Swift 1.1 is released
Apr2015 - Swift 1.2 is released
Mar 2017 - Apple releases Swift 3.1
June 2017 - Apple announces Swift 4.0 at WWDC 17

Is Swift Object Oriented Programming?
Yes! Swift is an Object-Oriented Programming language.

What's New Features in Swift 4.0?
ü  Faster, easier to use Strings that retain Unicode correctness
ü  Smart key paths for type-safe, efficient, extensible key value coding for Swift types
ü  Added some enhancements to creating dictionary and Set types
ü  Extends to supports of serialization to Struct
ü  Tuples and multiple return values
ü  Structs that support methods, extensions, and protocols
ü  Native error handling using try/catch/throw

What Are the Advantages of Swift?
ü  Swift is safe
ü  Swift is fast
ü  Swift is open source
ü  Swift is approachable
ü  Swift is easy to learn

What Is The Difference Between Swift And Objective-C Language?
Swift Programming-
In a swift programming, the variables and constants are declared before use.
In a swift programming, “var” keyword used for variable and “let” keyword for constant.
In a swift programming, no need to end code with semi-colon
In a swift programming, does not require creating a separate interface like Objective-C.
In a swift programming, we can define methods in class, structure or enumeration.

Objective-C Programming-
In objective-C programming, we need to end code with semi-colon
In objective-C programming, we can declare constant as int and variable as NSString.

How You define variables in Swift?
The “var” keyword is used for declaring variables and variables must be declared before they are used.
var helloMsg = "This is Anil, How Are You?"

What Is the significance of “?” in swift?
The question mark (?) is used during the declaration of a property. If the property does not hold a value, the question mark (?) helps to avoiding application errors.

Example looks like -
class Employee {
  var certificate : [Certificates]?

let employee = Employee();

Example 2 -
let middleName : String? = nil
let lastName : String = "Singh"
let name : String = middleName ?? lastName

What Is Type Aliasing in Swift?
This borrows very much from C/C++. It allows us to alias a type, which can be useful in many particular contexts.
typealias sample = UInt16

What Is a deinitializer in Swift?
If you want to perform an additional clean-up of your classes, it is possible to define a block called deinit.

Syntax -
deinit {
  //Your cleanup statement here.

How Multiple Line Comment Can Be Written In Swift?
The Nested multiline comments enable you to comment out large blocks of code quickly and easily.
Use an opening (/*: ) and closing ( */) comment and it looks like -

     The above forward slash (/) and an asterisk (*) then a colon (:) is opening comment - (/*:)
     The below an asterisk (*) and forward slash is closing comment – (*))

What Is difference between “let” and “var” declaration?
The “var” keyword is used for declaring variables while “let” keyword is used to declare constants.
Both variables and constants must be declared before they are used. 

Once assigned value in the constant, cannot be change but once assigned value in the variables, it can be change.
Var helloMsg = “This is Anil, How Are Yo?” // declared variable
let port = 8080; //declared  constant

How To convert NSMutableArray to Swift Array in swift?
The following code looks like -
var mutableArray = NSMutableArray(array: ["Anil", "Sunil", "Sushil"])
var swiftArray = mutableArray as NSArray as! [String]

How To convert NSArray to NSMutableArray in swift?
The following code looks like -
let array_1: NSArray = [“Anil”, “Sunil”, “Sushil”]
var mutableArray = NSMutableArray(array:array_1)


By Anil Singh | Rating of this article (*****)

Popular posts from this blog

39 Best Object Oriented JavaScript Interview Questions and Answers

Most Popular 37 Key Questions for JavaScript Interviews. What is Object in JavaScript? What is the Prototype object in JavaScript and how it is used? What is "this"? What is its value? Explain why "self" is needed instead of "this". What is a Closure and why are they so useful to us? Explain how to write class methods vs. instance methods. Can you explain the difference between == and ===? Can you explain the difference between call and apply? Explain why Asynchronous code is important in JavaScript? Can you please tell me a story about JavaScript performance problems? Tell me your JavaScript Naming Convention? How do you define a class and its constructor? What is Hoisted in JavaScript? What is function overloadin

List of Countries, Nationalities and their Code In Excel File

Download JSON file for this List - Click on JSON file    Countries List, Nationalities and Code Excel ID Country Country Code Nationality Person 1 UNITED KINGDOM GB British a Briton 2 ARGENTINA AR Argentinian an Argentinian 3 AUSTRALIA AU Australian an Australian 4 BAHAMAS BS Bahamian a Bahamian 5 BELGIUM BE Belgian a Belgian 6 BRAZIL BR Brazilian a Brazilian 7 CANADA CA Canadian a Canadian 8 CHINA CN Chinese a Chinese 9 COLOMBIA CO Colombian a Colombian 10 CUBA CU Cuban a Cuban 11 DOMINICAN REPUBLIC DO Dominican a Dominican 12 ECUADOR EC Ecuadorean an Ecuadorean 13 EL SALVADOR

25 Best Vue.js 2 Interview Questions and Answers

What Is Vue.js? The Vue.js is a progressive JavaScript framework and used to building the interactive user interfaces and also it’s focused on the view layer only (front end). The Vue.js is easy to integrate with other libraries and others existing projects. Vue.js is very popular for Single Page Applications developments. The Vue.js is lighter, smaller in size and so faster. It also supports the MVVM ( Model-View-ViewModel ) pattern. The Vue.js is supporting to multiple Components and libraries like - ü   Tables and data grids ü   Notifications ü   Loader ü   Calendar ü   Display time, date and age ü   Progress Bar ü   Tooltip ü   Overlay ü   Icons ü   Menu ü   Charts ü   Map ü   Pdf viewer ü   And so on The Vue.js was developed by “ Evan You ”, an Ex Google software engineer. The latest version is Vue.js 2. The Vue.js 2 is very similar to Angular because Evan You was inspired by Angular and the Vue.js 2 components looks like -

nullinjectorerror no provider for httpclient angular 17

In Angular 17 where the standalone true option is set by default, the app.config.ts file is generated in src/app/ and provideHttpClient(). We can be added to the list of providers in app.config.ts Step 1:   To provide HttpClient in a standalone app we could do this in the app.config.ts file, app.config.ts: import { ApplicationConfig } from '@angular/core'; import { provideRouter } from '@angular/router'; import { routes } from './app.routes'; import { provideClientHydration } from '@angular/platform-browser'; //This (provideHttpClient) will help us to resolve the issue  import {provideHttpClient} from '@angular/common/http'; export const appConfig: ApplicationConfig = {   providers: [ provideRouter(routes),  provideClientHydration(), provideHttpClient ()      ] }; The appConfig const is used in the main.ts file, see the code, main.ts : import { bootstrapApplication } from '@angular/platform-browser'; import { appConfig } from '

React | Encryption and Decryption Data/Text using CryptoJs

To encrypt and decrypt data, simply use encrypt () and decrypt () function from an instance of crypto-js. Node.js (Install) Requirements: 1.       Node.js 2.       npm (Node.js package manager) 3.       npm install crypto-js npm   install   crypto - js Usage - Step 1 - Import var   CryptoJS  =  require ( "crypto-js" ); Step 2 - Encrypt    // Encrypt    var   ciphertext  =  CryptoJS . AES . encrypt ( JSON . stringify ( data ),  'my-secret-key@123' ). toString (); Step 3 -Decrypt    // Decrypt    var   bytes  =  CryptoJS . AES . decrypt ( ciphertext ,  'my-secret-key@123' );    var   decryptedData  =  JSON . parse ( bytes . toString ( CryptoJS . enc . Utf8 )); As an Example,   import   React   from   'react' ; import   './App.css' ; //Including all libraries, for access to extra methods. var   CryptoJS  =  require ( "crypto-js" ); function   App () {    var   data