SwiftUI: Properties

In SwiftUI, you have the flexibility to add properties to any view to enhance its functionality. Let’s explore how properties can be used in SwiftUI views. import SwiftUI struct ContentView: View { let name = "Flavio" var body: some View { Text("Hello, \(name)!") .font(.largeTitle) } } In the above code snippet, we declare a constant property name of type String and assign it the value “Flavio”. This property is then used within the Text view to display a personalized greeting....

SwiftUI: Spacing

In the previous tutorial about SwiftUI, we discussed how views can be organized using stacks. Now, let’s dive into the topic of spacing. When using a VStack, you might notice that there is no space between the Text views by default. This is the default behavior of a VStack. However, you can adjust the spacing between the views by providing a spacing parameter: VStack(spacing: 100) { Text("Hello World") Text("Hello again!") } In this example, we set the spacing to 100 points, resulting in a 100-point gap between the views within the VStack....

SwiftUI: The ForEach View - Simplifying Iteration in SwiftUI

The ForEach view is a powerful tool in SwiftUI that allows us to easily iterate over an array or a range and generate views based on the iteration. It simplifies the process of creating repetitive views, such as lists or grids, by reducing the code required. Let’s start with a basic example. We can use ForEach to generate three Text views that display the numbers from 0 to 2: ForEach(0..<3) { number in Text("\(number)") } In this example, we use the ....

SwiftUI: Using Alerts to Display Messages

Alert messages are a useful way to provide feedback to users and aid in debugging applications. In SwiftUI, you can leverage the .alert() modifier to display alerts based on certain conditions. Let’s consider an example where we have a Button with an associated counter: import SwiftUI struct ContentView: View { @State var count = 0 var body: some View { Button("Count: \(count)") { self.count += 1 } .font(.title) } } Suppose we want to show an alert message when the count reaches 10....

Why I chose to dive into iOS development

As a developer with a passion for building things, I’ve always enjoyed exploring the software and hardware aspects of creating new technologies. While I have a background in web development, my decision to venture into iOS development doesn’t mean I’m abandoning it. Instead, I see it as an opportunity to explore a whole new world of possibilities with Swift. One of my main goals is to help aspiring developers in their journey....