How to use privacySensitive in swiftUI?

By | August 27, 2024

SwiftUI lets us mark some parts of our view as containing sensitive information, which in practice allows us to hide or show it more easily using redaction. To use this feature in your code, first add the privacySensitive() modifier to any views that should be hidden, then apply the .redacted(reason: .privacy) modifier at a higher place in your view… Read More »

3 Simple ways to use Debouncer in Flutter

By | August 26, 2024

Watch Video Tutorial Using Simple Timer Create a simple debouncer class Implementation: Using ValueNotifier Implementation: Using “Simple Debouncer” package First Add easy_debouncer package in your dependencies https://pub.dev/packages/easy_debounce Source Code https://github.com/MrVipinVijayan/flutter_tutorials/tree/feat/debounce

Placeholder for text using redacted()

By | August 25, 2024

In our view we can mark a text as placeholder, meaning that it gets rendered but masked out with gray to show it isn’t final content. This is provided through the redacted(reason:) modifier, along with an unredacted() modifier you can use to override redaction as needed You can redact several things in your view at once, just by using redacted(reason:) on… Read More »

Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. Find the minimum element in O(log N) time. You may assume the array does not contain duplicates.

By | August 22, 2024

To find the minimum element in a rotated sorted array in O(log⁡N)O(\log N)O(logN) time, you can use a modified binary search approach. The key observation is that even though the array is rotated, one part of the array will still be in sorted order. By comparing elements in the middle of the array with the… Read More »

How to adjust text alignment using multilineTextAlignment()

By | August 13, 2024

Like many other text UI’s SwiftUI’s Text wraps across multiple lines, they align to their leading edge by default. You can change that behavior, by using swiftUI’s ‘multilineTextAlignment()’ modifier to specify an alternative like .center, .trailing etc. For example, this will center several lines of text as they wrap across lines: Let’s use a picker… Read More »

Format text inside text view.

By | August 12, 2024

From iOS 13 onwards apple has introduced text formatting API named ‘Format’ and it is capable of showing dates, arrays and measurements and more. If you use the .list() format type with an array of strings, you can get neatly formatted lists such as “Jay, Modi, and Webber”. For example, this will print ingredients lists correctly no… Read More »

How to add advanced text styling using AttributedString in swiftUI?

By | August 5, 2024

In our previous post we talked about styling swiftUI text views with fonts, colors, line spacing and more. This time we will look deep into ‘AttributedString’. SwiftUI’s ‘Text’ view is able to render more advanced strings created using ‘AttributedString’ struct. This includes adding underlines, strike through, web links, background colours etc. We will show you… Read More »

Given a 2D board of characters and a word, find if the word exists in the grid.

By | August 5, 2024

The word can be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once. For example, given the following board: exists(board, “ABCCED”) returns true, exists(board, “SEE”) returns true, exists(board, “ABCB”) returns false. Python def exist(board, word):    if not board:        return False   … Read More »

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 22, 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 »