Styling swiftUI text views with fonts, colors, line spacing and more

By | July 10, 2024

A text view draws a string in your app’s user interface using a body font that’s appropriate for the current platform. You can choose a different standard font, like title or caption, using the font(_:) view modifier. Text views give us predictably wide range of controls in terms of how they look. They are also designed to work seamlessly alongside core apple… Read More »

How to customise NavigationStack background in swiftUI?

By | June 15, 2024

The view background can extend to the corners of the view. This will affect the navigation bar background. This will go behind large and inline navigation bars. For example, in below example the background colour is applied to the whole screen, but it is covering the navigation bar background too. The new initializer introduced with… Read More »

How do I implement pull to refresh in SwiftUI?

By | June 11, 2024

There are two main approaches to implementing pull-to-refresh functionality in SwiftUI, depending on your SwiftUI version and desired level of customization: 1. Using the built-in refreshable modifier (iOS 16+) If you’re targeting iOS 16 and above, SwiftUI offers a built-in refreshable modifier that simplifies pull-to-refresh functionality for List and ScrollView. Here’s how to use it:… Read More »

How to use ‘AsyncImage’ in swiftUI?

By | May 27, 2024

AsyncImage is a component introduced in SwiftUI to handle the loading and displaying of remote images asynchronously. It simplifies the process of fetching images from the web, handling the loading state, and displaying a placeholder until the image is ready. Here’s a detailed breakdown of how AsyncImage works, its customisation options, and usage examples. Basic… Read More »

Core data stack in swift

By | April 28, 2024

In Swift, Core Data is a powerful framework provided by Apple for managing the model layer objects in an application. A Core Data stack refers to the set of objects and configurations used to interact with the Core Data framework. The Core Data stack typically consists of three main components: 2. Persistent Store Coordinator (PSC):… Read More »

What are optionals in swift?

By | March 14, 2024

In Swift, optionals are a powerful feature that allows variables or constants to have a value or be nil, indicating the absence of a value. Optionals are represented using the Optional type, which is an enumeration with two cases: Some(Wrapped) to represent a value, and nil to represent the absence of a value. Here are… Read More »

What are higher order functions in swift ?

By | February 28, 2024

Higher-order functions in Swift are functions that take other functions as parameters or return functions as output. They enable a functional programming style by allowing you to compose functions, pass behavior as arguments, and manipulate collections with concise and expressive code. Here are some common higher-order functions in Swift with examples: map(_:): filter(_:): reduce(_:combine:): sorted(by:):… Read More »

How to setup a basic core data stack in swift?

By | February 22, 2024

Setting up a Core Data stack in Swift involves several steps, including creating a managed object model, setting up a persistent store coordinator, managed object context, and other components. Here’s a basic guide to setting up a Core Data stack in Swift: Create a Data Model: Generate NSManagedObject Subclasses: Initialize the Persistent Store Coordinator: Managed… Read More »

What is enum associated values in swift?

By | February 15, 2024

In Swift, enumerations (enums) are powerful constructs that allow you to define a group of related values. Associated values in Swift enums enhance their flexibility by enabling each enum case to carry additional data of varying types. This feature allows you to model more complex data structures and behaviors with enums. Here’s how you can… Read More »

What is protocol oriented programming in swift?

By | February 7, 2024

Protocol-oriented programming (POP) is an approach to software development in Swift that emphasizes the use of protocols to define interfaces and behavior, promoting code reuse, flexibility, and composability. POP encourages structuring code around protocols rather than classes, focusing on what types can do rather than what they are. Key concepts of protocol-oriented programming in Swift… Read More »

What is XCTest framework in iOS?

By | February 5, 2024

The XCTest framework is the testing framework provided by Apple for writing and running unit tests in iOS and macOS applications. It is part of the broader XCTest framework available in the Apple ecosystem. XCTest is commonly used with Swift and Objective-C to test various aspects of your code, ensuring its correctness, reliability, and maintainability.… Read More »

What is a frame and bounds of a UIView in swift?

By | February 1, 2024

In iOS development using UIKit, a UIView is a fundamental building block for constructing the user interface. Two important properties of a UIView are its frame and bounds. These properties define the size and location of the view within its superview. frame: In this example, myView is positioned at (50, 50) within its superview, and… Read More »

Implement a stack API using only a heap. A stack implements the following methods:

By | January 31, 2024

Recall that a heap has the following operations: To implement a stack using only a heap, you can use a max heap and maintain a counter to ensure that the order of elements is preserved. Here’s an example implementation in Python, Java, and JavaScript using the heapq module (Python), PriorityQueue (Java), and BinaryHeap (JavaScript): Python:… Read More »

Handling exception in Ruby

By | January 30, 2024

In Ruby, exception handling is done using the begin, rescue, else, and ensure blocks. Here’s a basic structure of a begin-rescue block: Let’s break down the components: Example with a specific exception: In this example: As with any language, it’s good practice to catch only the exceptions you expect and handle them appropriately. Avoid catching… Read More »

How to do exception handling in python?

By | January 29, 2024

Exception handling in Python is done using the try, except, else, and finally blocks. Here’s a basic structure of a try-except block: Let’s break down the components: Example with a specific exception: In this example: You can customize exception handling based on the specific requirements of your code. It’s generally a good practice to catch… Read More »

What are python name spaces?

By | January 27, 2024

In Python, a namespace is a container that holds a set of names (identifiers) and their corresponding objects. It serves as a mapping between names and objects, allowing you to organize and manage the scope of variables, functions, classes, and other identifiers in your code. Namespaces help avoid naming conflicts and provide a way to… Read More »

Given a string of parentheses, find the balanced string that can be produced from it using the minimum number of insertions and deletions

By | January 25, 2024

Given a string of parentheses, find the balanced string that can be produced from it using the minimum number of insertions and deletions. If there are multiple solutions, return any of them. For example, given “(()”, you could return “(())”. Given “))()(“, you could return “()()()()”. To find the balanced string with the minimum number… Read More »