Posts

Showing posts from May, 2021

Dictionaries In Swift

Image
 What’s a Dictionary?                     You can use a dictionary to store a collection of key-value information in your app. A dictionary is similar to an array in the sense that both store lists, also called collections, of items of the same type.                     A dictionary is a fundamental collection in Swift programming. With a dictionary you can store key-value data in your app. It’s a collection type, similar to array and sets, but completely different too. Let's see an example:- Here’s an example of a dictionary:                               The type of the scores dictionary is [String: Int]. That means that the type of the keys in the dictionary is String, and the type of its values is Int.    In the above example we haven’t explicitly provided the t...

Arrays in Swift Programming Language

Image
 Array In Swift Arrays are fundamental building blocks of apps.                      In computer programming, arrays are numbered lists (or “collections”) of items with the same type. A variable contains one value, and an array can hold many values. Let’s get started with the syntax to create an array.                     Swift arrays are applied for storing multiple values in ordered lists of any specific type. Swift set up strict checking mechanism which does not allow programmers to enter or insert any wrong type in an array even by mistake, i.e., arrays in swift programming are specific about the kinds of values they can store. The same value can appear in an array multiple times at different positions.  Shorthand syntax of arrays:                     The swift array can also be written in t...

Set Collection in swift

Image
  Sets In Swift                     A set stores distinct values of the same type in a collection with no defined ordering. You can use a set instead of an array when the order of items isn’t important, or when you need to ensure that an item only appears once. NOTE Swift’s Set type is bridged to Foundation’s NSSet class. For more information about using Set with Foundation and Cocoa, see Bridging Between Set and NSSet. Hash Values for Set Types :                     A type must be hashable in order to be stored in a set—that is, the type must provide a way to compute a hash value for itself. A hash value is an Int value that’s the same for all objects that compare equally, such that if a == b, the hash value of a is equal to the hash value of b.                     All of Swift’s basic types (such as Str...

Loop in Swift programming Language

Image
Concept of Loop in Swift Looping :-                     Looping, also known iteration is used in a program to repeat a specific block/segment of code(s). This reduces the tasks of writing the same thing again and again.  for condition increment loops:-                     The for-condition-increment loop is functionally the same as the 'for' loop in C. The loop consists of an initialization phase, a test, an increment, and a set of statements that are executed for every iteration of the loop. for initialization; condition; increment { statements } for in loops:-                      You use the for-in loop to iterate over sequences or collections of things, such as the elements of an array or dictionary, the characters in a string, or a range of numbers. Here's the general form is: for index in seque...

If Else In Swift Programming Language

Image
 IF ELSE IN SWIFT:-                     An if statement can be followed by an optional else if...else statement, which is very useful to test various conditions using single if...else if statement. When using if, else if, else statements, there are a few points to keep in mind:- An if can have zero or one else's and it must come after any else if's. An if can have zero to many else if's and they must come before the else. Once an else if succeeds, none of the remaining else if's or else's will be tested. The Swift if-else statement contains two statements:  if statement and  else statement. example: Output:- This is a positive number. This will be executed anyways.                     In swift, if else-if else statement is used to add alternative set of multiple else-if and single else statements for if condition. In case if condition fails (FALSE) then ...

What are the Functions in swift ?

Image
  Function In Swift                     Functions are self-contained chunks of code that perform a specific task. You give a function a name that identifies what it does, and this name is used to “call” the function to perform its task when needed.                     Swift’s unified function syntax is flexible enough to express anything from a simple C-style function with no parameter names to a complex Objective-C-style method with names and argument labels for each parameter. Parameters can provide default values to simplify function calls and can be passed as in-out parameters, which modify a passed variable once the function has completed its execution.                     Every function in Swift has a type, consisting of the function’s parameter types and return type. You can use this type like any ...