Posts

Swift Package Manager: Demystifying Targets and Libraries

Target vs Library If you'v dabbled with Swift Package Manager (SwiftPM), you've likely encountered targets and libraries in a Package.swift file and wondered what sets them apart. These concepts are essential to structuring your code effectively, especially as projects grow larger. In this post, we'll break down the difference between the two, explore how they're used, and walk through real-world examples that show how you can build scalable and modular Swift packages. What Exactly Is a Target? In SwiftPM, a target is the fundamental unit of code compilation. It's basically a module that consists of source files, dependencies, and optionally resources or tests. Targets are used internally within your package. For example: .target(name: "Logger") This line defines a module named Logger . You can import and use this module from other targets inside your package. And a Library? A library is a product. It’s what you offer to the outside world—other packag...

IOS Simulator Crash report

If your iOS app crashes in the Simulator during a test run, the crash report can be used for diagnosing the exact cause of the crash. By default, the crash reports for the app will be written to the ~/Library/Logs/DiagnosticReports directory. The crash reports can be uploaded as artifacts to assist with debugging the app crash on your local machine: - store_artifacts: path: ~/Library/Logs/DiagnosticReports

Palindrome check

A Palindrome is a word, phrase, or sequence that reads the same backward as forward. Ex: RaceCar, madam, mom, level We have two methods to check for a palindrome. 1. Reverse String Comparision: If we reverse a string and compare it with the given string, then if both the strings are equal, we can say the given string is a palindrome. func reversedString(input: String )-> String { var reversed = "" for char in input{ reversed = "\(char)" + reversed } return reversed } func isPalindrome( _ input : String )-> Bool { let reversed = reversedString (input: input) return reversed == input } Time Complexity: θ(n) Space Complexity: θ(n) 2. Character Comparision: We'll start comparing the first character with the last character, if both are equal we'll increment the left index & decrement the right index until we cross the middle character. If we successfully pass the middle character then the given s...

Binary Search

Image
 Problem: We have a sorted array and a key element, we need to find out if the key element is present in the array. If it exists return the index of that element or return -1 if it doesn't exist. If the array has repeated elements, the order of the index is not important. Example: Pseudocode: Step 1: Initialise low = 0, high = array.count - 1 Step 2: Run a loop until low <= high Step 3: Compute middle index             middle  = (low + high) / 2 Step 4: If array[middle] == x, we found the index, then             return x Step 5: If  x < array[middle], x lies in the first half of the array, then             high = middle - 1 ...

Stack Problem - Balancing of Symbols

Stack Problem - Balancing of Symbols Problem: Given an expression string exp , write a program to examine whether the pairs and the orders of “{“,”}”,”(“,”)”,”[“,”]” are correct in exp. Example : Input : exp = “[()]{}{[()()]()}” Output : Balanced Input : exp = “[(])” Output : Not Balanced Algorithm: Create a stack. while ( end of input is not reached ) { If the character read is not a symbol to be balanced, ignore it. If the character is an opening delimiter like ( , {  or [ , PUSH it into the stack. If it is a closing symbol like ) , } , ] , then if the stack is empty report an error, otherwise POP the stack. If the symbol POP-ed is not the corresponding delimiter, report an error. At the end of the input, if the stack is not empty report an error. Implementation : func balancingOfSymbols(string: String )-> Bool { guard string. count > 0 else { return false } let symbols:[ Character : Character ] = [ "{" : "}...

Stacks

What is a Stack ? A Stack ADT is an ordered list in which insertion and deletion are done at the top end of the list. A stack follows LIFO(Last In First Out) Principle i.e, the last element inserted is the first one to be deleted. Why do we need Stack? Well, in many algorithms you want to add objects to a temporary list at some point and then pull them off this list again at a later time. Often the order in which you add and remove these objects matters. Applications of Stack Balancing of symbols Infix-to-Postfix conversion Evaluation of postfix expression Implementing function calls(Recursive) Forward and Backward feature in a browser. Redo & Undo sequence in a text editor. Matching tags in HTML & XML. Used in other algorithms like Tree traversal, Tower of Hanoi, Stock span, N Queens, etc. Stack Operations Main stack operations Push : Inserts data onto stack Pop : Removes and returns the last inserted element from the stack. Auxiliary stack operation...

IOS Q&A -The Basics#01

IOS Interview Questions and Answers The Basics#01 1. What are the Key Features of the Swift programming language? Modern : Swift is a result of the latest research on programming languages, combined with decades of experience building Apple platforms. Also, Swift is continuously evolving. Safe : Swift is a type-safe language which means, If we pass a String to a variable of type Int by mistake, then Swift throws a compile-time error. Also, it’s a static programming language i.e. any variable or a constant should be declared or inferred to a specific type at the compile time. Fast : Swift was built to be fast using the incredibly high-performance LLVM compiler technology. There are claims that Swift is 2.6x faster than Objective-C and 8.4x faster than Python. Expressive : Swift is called Syntactic sugar because it makes the language “Sweeter” for developer use. Swift offers a simplified syntax and grammar that is easy to read and write. Open source : In 2015 , Swi...