New Features in Swift 4

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)

print(mutableArray)


ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..

My Tech Blog - https://www.code-sample.com/
My Books - Book 1 and Book 2

www.code-sample.com/. Powered by Blogger.
^