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 , width : 70 , height : 70 ), CGRect ( x : 110 , y : 20 , width : 60 , heigh

Ios Algorithm Interview Questions and Answers

 

1. What is Big O Notation, What Time and Space Complexity 

Answer:- Big O Notation is a mathematical notation describe the limiting behavior of a function when the argument tends towards a particular value or infinity.

बिग ओ नोटेशन एक गणितीय संकेतन है जो किसी फ़ंक्शन के सीमित व्यवहार का वर्णन करता है जब तर्क किसी विशेष मान या अनंत की ओर जाता है।

"Big O Notation is key in Algorithms and Data Structure,  Big O Notation describe the complexity of your code using algebraic terms."

"बिग ओ नोटेशन एल्गोरिदम और डेटा संरचना में महत्वपूर्ण है, बिग ओ नोटेशन बीजगणितीय शब्दों का उपयोग करके आपके कोड की जटिलता का वर्णन करता है।"


Big O Notation describe the worst-case scenarios with the complexity

1. O(1) :-  Constant Complexity -> Execution time does not depend on data size.

For Example -  0(1) operations

let array = [1, 2, 3, 4, 5, 6]

Accessing an element in an array by index.

print(array[0])

print(array[2])

Here is an example of an O(1) constant time complexity function in Swift:

func getFirstElement<T>(of array: [T])->T?{

    return array.first

}


let number = [10,20,30,40,50,60]


if let firstElement = getFirstElement(of: number){

    print("The first element is \(firstElement)")

}else{

    print("array is Empty")

}


Comments