Swift Extensions by Example - Swift Programming Language 1. Introduction Extensions add new functionality to an existing class, structure, enumeration, or protocol type. This includes the ability to extend types for which you do not have access to the original source code. Declare extensions with the extension keyword Format of Extension extension SomeType { // new functionality } An extension can...
Swift Initializers and Deinitializers - Swift Programming Language 1.Initializers Initialization is the process of preparing an instance of a class, structure, or enumeration for use. This process involves setting an initial value for each stored property on that instance and performing any other setup or initialization that is required before the new instance is ready for use....
Swift Control Flow by Example - Swift Programming Language In Swift, there are three kinds of statements: simple statements, compiler control statements, and control flow statements. Simple statements are the most common and consist of either an expression or a declaration. Compiler control statements allow the program to change aspects of the compiler’s behavior and include a conditional...
Swift Methods by Example - Swift Programming Language Methods are functions that are associated with a particular type. Classes, structures, and enumerations can all define instance methods, which encapsulate specific tasks and functionality for working with an instance of a given type. Classes, structures, and enumerations can also define type methods, which are associated with the type itself....
Swift Properties by Example - Swift Programming Language Properties associate values with a particular class, structure, or enumeration. Suppose if we need to change or access an iVar in your class using an object of your class, then there should be getter and setter methods assigned to the iVar. A property is used mainly when other objects need...
Swift Classes and Structures by Example - Swift Programming Language 1. Introduction Classes and structures are general-purpose, flexible constructs that become the building blocks of your program’s code. You define properties and methods to add functionality to your classes and structures by using exactly the same syntax as for constants, variables, and functions. In Swift, you define a class...
Swift Access Control by Example - Swift Programming Language Access control restricts access to parts of your code from code in other source files and modules. This feature enables you to hide the implementation details of your code, and to specify a preferred interface through which that code can be accessed and used. You can assign specific access levels...
Swift Advanced Operators (Bitwise) by Example - Swift Programming Language Swift provides a several advanced operators bitwise and bit shifting to perform a more complex operations. In swift, Arithmetic operators won’t show the overflow value by default. To opt the behavior of overflow, swift uses the second set of advanced operators such as the addition operators +& and all...
Swift Dictionary by Example - Swift Programming Language Overview A collection whose elements are key-value pairs. A dictionary is a type of hash table, providing fast access to the entries it contains. Each entry in the table is identified using its key, which is a hashable type such as a string or number. You use that key to...
Swift Set by Example - Swift Programming Language Overview An unordered collection of unique elements. You use a set instead of an array when you need to test efficiently for membership and you aren’t concerned with the order of the elements in the collection, or when you need to ensure that each element appears only once in...
Swift Array by Example - Swift Programming Language Overview An ordered, random-access collection. you use the Array type to hold elements of a single type, the array’s Element type. An array can store any kind of elements—from integers to strings to classes. 1. Creating and Initializing an Array 1.1 Creating an Array Swift makes it...
Swift Double by Example - Swift Programming Language Overview Double represents a 64-bit floating-point number. Double has a precision of at least 15 decimal digits, whereas the precision of Float can be as little as 6 decimal digits. Swift always chooses Double (rather than Float) when inferring the type of floating-point numbers.If you combine integer and floating-point...
Swift Float by Example - Swift Programming Language Overview Floating-point numbers are numbers with a fractional component, such as 3.14159, 0.1, and -273.15. Float represents a 32-bit floating-point number. 1. Converting Floating-Point Values 1.1 init(_:) Creates a new instance that approximates the given value. let x: Double = 21.25 let y = Float(x) print(...
Swift Int by Example - Swift Programming Language Overview A signed integer value type. On 32-bit platforms, Int is the same size as Int32, and on 64-bit platforms, Int is the same size as Int64. 1. Declaring Constants and Variables Constants and variables must be declared before they’re used. You declare constants with the let keyword and...
Swift String by Example - Swift Programming Language Overview A string literal is a sequence of characters surrounded by double quotes ("). 1. Creating and Initializing Strings 1.1 Initializing Strings let name = "vineeta" print(name) String interpolations are string literals that evaluate any included expressions and convert the results to string form. String interpolations give...