Swift is a programming language developed by Apple Inc for the development of Apple iOS and OS X development. The Swift programming language adopts the best of C and Objective-C without the constraints of C compatibility. Writing the Swift code is simple, and interactive. The designing of Swift programming language is highly secured and also produces the high-speed software. This language has greater robustness and stability which provides source code compatibility. The following cheat sheet gives the knowledge of the syntax of the Swift programming language. Find freelancers to get started using this programming language.

 Basic Syntax of Swift Programming Language

var someDict = [KeyType: ValueType]()

Variable in Swift Programming Language

The variable in the Swift programming language has a specific type which finds the size and layout of the variables memory and variable are also the values stored in that memory. Following are the types of the Variables.

  • Int or UInt- The Int or UInt is for specifying the whole numbers.
  • Float- Float is for specifying the 32-bit floating point number.
  • Double – This data type is for representing a 64-bit floating-point number.
  • Bool- This is for representing the Boolean value which defines only two values that is true or false.
  • String- String is the collection of characters.
  • Characters- This is the single character string literal.

Tuples in Swift Programming language:

The Swift programming language also introduces the Tuples types that are very useful to combine the multiple values in a single compound value.

Here’s the syntax of Tuple declaration –

var TupleName = (Value1, value2,… any number of values)

Constants in Swift Programming Language:

The Swift programming language also declares the constant variable. The term constants variable is same as the simple variable except the fact that you can’t modify this value after their definition. In Swift programming language the constants variables are declared using the let keyword. Following are the syntax of the constants in Swift.

let constantName = <initial value>

Operators:

Operators are the collection of symbols that work on the operand. The operators tell the compiler to perform the specific mathematical and logical operation.

  • Arithmetic Operators
  • Comparison Operators
  • Logical Operators
  • Bitwise Operators
  • Assignment Operators
  • Range Operators
  • Misc Operator

String in Swift Programming Language

The string is the collections of characters. Following are the syntax for the creation of String.

// stringA can be modified

var stringA = “Hello World”

stringA + = “–Readers–”

print( string )

// stringB can not be modified

let stringB = String(“Hello World”)

stringB + = “–Readers–”

print( stringB )

 Array in Swift Programming

The array is the collection of similar type of data types stored sequentially. In Swift programming language if you will assign the created array to a variable then it will always be mutable it means that you can change it by removing and adding the items.

Following are the syntax for the creation of the array.

var someArray = [SomeType]()

Function in Swift Programming

A function is the block of statements that are organised together to perform the task. The function declaration in Swift programming instructs the compiler about the function’s name, return type, and parameters. Function definition covers the actual body of the function. Following are the syntax for function definition.

func funcname(Parameters) -> returntype {

Statement1

Statement2

Statement N

return parameters

}

Inheritance in Swift Programming

Inheritance is one of the object-oriented concepts. The inheritance concept derives the new class from existing class.  The classes of inheritance are two types that are Sub class and Super class.

  • Sub Class- The sub class inherits the functions and methods from other class.
  • Super class- The super class consists of the classes, methods, functions and other classes inherit the properties of the super classes.

Closure in Swift Programming Language

In Swift programming language closure is similar to self-contained functions structured in the blocks and is called anywhere in the program such as C and Objective-C languages. The syntax style of the closure consists of an interfering parameter and return value types from context. It follows the shorthand argument names. Following are the syntax for Closure. Find freelancers to get started using this programming language.

{

(parameters) −> return type in

statements

}

Summary:

This article is on the Swift programming cheat sheet. The above cheat sheet covers the most important basic and advanced concept of the Swift programming language. This cheat Sheet is useful for that programmer who has basic knowledge of Swift programming language but doesn’t remember the syntax of the programming language.

 

Kitty Gupta