Skip to main content

Custom Loader (Activity Indicator) in Swift

Creating a custom activity indicator in Swift allows you to tailor the appearance and behavior of your loading spinner to fit the style of your app. Here's a step-by-step guide to creating a simple custom activity indicator using UIView Step 1: Create a New Swift File for the Custom Activity Indicator Create a new Swift file and name it  RotatingCirclesView.swift . Add the following code to define a custom UIView subclass for your activity indicator: // //   RotatingCirclesView.swift //   Welcome In // //   Created by Praveen Kumar on 05/09/24. // import UIKit class RotatingCirclesView : UIView {          let circle1 = UIView ( frame : CGRect ( x : 20 , y : 20 , width : 60 , height : 60 ))     let circle2 = UIView ( frame : CGRect ( x : 120 , y : 20 , width : 60 , height : 60 ))          let position : [ CGRect ] = [ CGRect ( x : 30 , y : 20 , width : 60 , height : 60 ), CGRect ( x : 60 , y : 15 ,...

Control Flow Statements - statements used in swift


List out what is the control transfer statements used in swift

Control flow statements are used to control the flow of execution in a program. There are several types of control flow statements in Swift, including loop statements, branch statements, and control transfer statements. 
1.       Loop statements allow a block of code to be executed repeatedly
2.        Branch statements allow a certain block of code to be executed only when certain conditions are met
3.       Control transfer statements provide a way to alter the order in which code is executed.
4.       Swift provides a do statement to introduce scope, and catch and handle errors,
5.       Defer statement for running cleanup actions just before the current scope exits.



Loop Statements -

Loop statements allow a block of code to be executed repeatedly, depending on the conditions specified in the loop.
Swift there are three loop statements
·         For-in statement
·         While statement
·         Repeat-while statement
A for-in statement allows a block of code to be executed once for each item in a collection that conforms to the Sequence protocol.
for item in collection {
    statements
}
A while statement allows a block of code to be executed repeatedly, a condition remains true.
while condition {
    statements
}
A repeat-while statement allows a block of code to be executed one or more times, then condition true.
repeat {
    statements
} while

Branch Statements

Branch statements allow a certain block of code to be executed only when certain conditions are met. Swift have three branch statements
·         if statement
·         guard statement
·         Switch statement
Guard Statement
A guard statement is used to transfer program control out of a scope if one or more conditions aren’t met.
guard condition else {
    statements
}
Switch Statement
A switch statement allows certain blocks of code to be executed depending on the value of a control expression.
switch control expression {
case pattern 1:
    statements
case pattern 2 where condition:
    statements
case pattern 3 where condition,
     pattern 4 where condition:
    statements
default:
    statements
}

Control Transfer Statements

Control transfer statements can change (alter) the order in which code in your code is executed.
 Swift have five control transfer statements
·         break statement,
·         continue statement - A continue statement ends program execution of the current iteration of a loop statement 
·         fallthrough statement
·         return statement
·         throw statement

Comments

  1. Thanks for the useful information, give more updates like First time I visit your site really nice, here after a daily visit.
    ecommerce website development company in chennai

    ReplyDelete

Post a Comment