Category: Learning Swift Series
-
Type ‘NSNotification.Name’ has no member ‘UIResponder’ Error iOS
Delete the text NSNotification.Name. written before the UIResponder to remove the error.
-
Data types in Swift
Swift provides us with both built-in and user defined data types. The most common data types available with Swift are as follows: Integer Float Double Boolean Optional Tuple Character String
-
Learning Swift Series: Part 2 – Optionals
In this series we will learn about Optionals in Swift. Optionals in Swift Forced Unwrapping of Optional Optional binding Implicitly Unwrapped Optional
-
Optional binding in Swift
If and while statements can be used to check whether an optional has a value and if yes, then extract the value and make it available for temporary constants or variables. We can use both constants and variables with optional binding. We don’t have to use ! to extract the optional value in optional binding. Constants and […]
-
Implicitly Unwrapped Optional in Swift
If the optional variable(or constant) will always have a value but not nil then we can unwrap the optional during its declaration itself by using ! instead of ? after the type. This will avoid unnecessary checks and unwrapping of optional value each time it is accessed. We can still use implicitly unwrapped optional to […]
-
Forced Unwrapping of Optional in Swift
If statements are used to compare the optional value to nil .If there is a value then we can obtain the value stored in the optional by adding ! at the end of the optional type. This is known as forced unwrapping of optional value. Always make sure that the optional has a non-nil value […]
-
Learning Swift Series: Part 1 – Basics
In part one of Learning Swift Series, we will deal with the following topics that cover basics of Swift language: Constants and Variables Data types Type safety and Type Inference Type annotation Type alias Comments Semicolon Assertions and Preconditions
-
Type safety and Type inference in Swift
Swift is a type safe language. It performs type checks while compiling our code and flags of any errors due to mismatched types. We don’t have to specify the type of constants and variables every time. Swift can infer the type of variables and constants when they are assigned with an initial value. This is […]
-
Semicolon in Swift
Swift does not require us to use semicolon at the end of each statements although we can do so without triggering any error but we must separate multiple statements in a single line with a semicolon to prevent error.
-
Comments in Swift
Comments are used to include non-executable text in code. Single line Comment begins with two forward slashes . // Multiline Comment begins with a forward slash followed by an asterisk and ends with an asterisk followed by a forward slash. /* some comments */ Nested Multiline Comment can include within it multiline comments and it starts with […]