How to use SwiftUI ForEach with index

In order to create views from a collection of data we use ForEach in SwiftUI. Sometimes we need index of current element in ForEach, we can use range, indices or enumerated() method. ForEach Index using enumerated() If we want to access both index and element in closure then enumerated() method can help us to achieve […]

How to use ForEach in SwiftUI to create views

If we want to create views from an array of data then ForEach in SwiftUI helps us to iterate over the array and generate view for each element in it. Suppose we want to create 6 views in a VStack. We can use close range from 0…5 as parameter in ForEach for this purpose and […]

How to create SwiftUI List View

A List view in SwiftUI is a container which helps us to display static or dynamic data in a scrollable column. By default we get standard styling of List. Let us create a simple List with static data to illustrate it. This simple List with static data will look like Dynamic List View We use […]

SwiftUI button with Image – Tappable Image button

In SwiftUI, creating buttons is very simple and straightforward. Button with image in SwitfUI is created using the same Button view, which we use for text-based buttons. However, instead of providing a text label, we specify an image as the label. Using this approach we can transform any desired icon or image into an interactive, […]

SwiftUI ScrollView scroll to position of a specific view’s location

To programmatically scroll to a specific position within a ScrollView, SwiftUI provides the ScrollViewReader and scrollTo method. Now, let’s walk through the process of using ScrollView to scroll to the position of a specific view in SwiftUI: Here’s a basic example demonstrating how to use ScrollView to scroll to the position of a specific view […]

How to add SwiftUI scrollview for horizontal and vertical scrolling

SwiftUI ScrollView is a container view that allows users to scroll through a collection of views vertically, horizontally, or in both directions. It provides a way to display content that exceeds the available screen space, enabling users to view all the content by scrolling. Key features of SwiftUI’s ScrollView include: Vertical ScrollView To create a […]

Add image to view controller Xcode (Storyboard)

To add an image to a view controller, you can first open the object library by clicking on the plus icon at the top. From there, you can search for UIImageView and then drag and drop it onto the view controller. To set the constraints of the UIImageView, you can click on the bottom pointed […]

How to use ChatGPT to write code

ChatGPT can assist you with writing code by providing suggestions, generating code snippets, and helping with problem-solving. You can interact with ChatGPT for: An example for each point will make it more clear. Code Generation Suppose you want to write a Python code snippet that calculates the factorial of a number. You can interact with […]