How can you make a property optional in Swift?
We have to declare a question mark ??’ in the code to make a property optional. If a property doesn’t have a value, then the symbol ? helps to avoid the runtime error.
What are the different collection types available in Swift?
There are two varieties of collection types in Swift:
Array: In Swift, you can create an array of single type or an array of multiple type.
Dictionary: In Swift, dictionary is similar to hash table in other programing language. You can store a key-value pair in a dictionary and access the value by using the key.
Explain Dictionary in Swift.
Swift Dictionary is used to store the key-value pairs and access the value by using the key. It is just like hash tables in other programming languages.
What are the different control transfer statements used in Swift?
Swift language consists of following Control transfer statements:
- Continue
- Break
- Fallthrough
- Return
What are the Half Open Range operators in Swift?
Swift supports several types of operators. One of them is Half Open Range operator. The half open range operator specifies a range between two values a and b (a<b) where b is not included. It is known as half open range operator because it contains its first value only not the final value.
What is Inheritance in Swift?
Inheritance is a process in which a class can inherit properties, methods and other characteristics from another class. Inheritance is supported in Swift programming language. There are two types of classes in Inheritance in Swift:
Sub class: The class which inherits the properties from other class is called child class or sub class.
Super class: The main class from where the subclass inherits the properties is known as parent class or super class.
How would you define variables and constants in Swift programming language?You have to declare variables and constants before using it. Constants are declared by using let keyword and variables by var keyword.
You have to declare variables and constants before using it. Constants are declared by using let keyword and variables by var keyword.
What do you mean by Optional Chaining in Swift?
In Swift programming language, Optional Chaining is a process of querying and calling properties. You can chain multiple queries together, but if any link in the chain is nil then, the entire chain fails.
What are functions in Swift?
Functions are the set of codes used to perform specific task. In Swift programming language, functions are used to pass local as well global parameter values inside the function’s call.
In Swift4, functions can be categorized in two types:
- User Defined Functions
- Built-in Functions (Library Functions)
Explain the different features of Swift programming language?
- Swift is very easy to learn and precise to use. It provides a safe programming approach.
- In Swift programming language, variables and constants must be initialized before use.
- Automatic memory management.
- Swift uses “switch” function instead of “if” statement for conditional programming.
- Swift follows Objective-C like syntax.
- It checks Arrays and integers for overflow.