With iOS 14, Apple gives you the ability to use lazy stacks in SwiftUI. While HStack and VStack load the content right away, LazyHStack and LazyVStack load the content as you scroll.
The Navigation View in SwiftUI allows you to switch between views in a hierarchical way using the Navigation Bar, large title and swipe gesture.
In this tutorial, we’ll learn how to open links when a user clicks an element. Links can open in the default browser. The link view takes in two parameters, the first one is the title and the second one is the destination which is the URL.
The native color picker provided by SwiftUI displays the currently selected color and a floating color picker which allows users to select a new color from the color wheel.
The DatePicker allows users to set a particular date using a scrolling wheel. With SwiftUI 2, you also get access to the GraphicalDatePickerStyle() which displays a calendar as well as time.
With SwiftUI, you can add the hoverEffect and onHover modifiers to any view. These allow us to detect when the user is hovering an item. This is an interaction that is specific to iPadOS and macOS since it requires a pointing device like the trackpad or mouse.
Just like in design tools and React, SwiftUI is component-based. To keep your code clean and reusable, you should turn them into components. SwiftUI gives you the ability to Extract Subview. This allows you to turn complex code into smaller chunks of code which leads to the code looking more organized and easier to read.
When you work with multiple components and need to synchronize the states, you’ll need to use Binding. In this tutorial, I’ll show you how to bind the states and set a default value for a Preview.
Working with static data allows you to quickly prototype and test realistic data before implementing the full API. In this tutorial, we’ll learn how to set the Data Model, set sample data and loop through the data.
With SwiftUI, you can present a modal view that takes the entire portion of the screen instead of the modal sheets that you see since iOS 13.
In SwiftUI, you can hide the status bar by using the .statusBar modifier. This can be applied to any view, such as the Text.
SwiftUI comes with a unique and effortless way to create a beautiful placeholder UI while lazy loading your app content.
Horizontal scrolling is common in iOS and SwiftUI makes it super easy to set it up. On top of that, you can easily add animation to your scroll by using GeometryReader and rotation3DEffect.
How to customize your Animation timing with the repeatCount, repeatForever, speed and delay modifiers. This is a great technique for creating looping loading animation, sequencing multiple animations or creating a nice intro animation.
In SwiftUI, you can trigger a change of tab from any element of any view by using the selection tags and setting a binding with child views.
In SwiftUI, you can dynamically detect the status bar and tab bar height by using the GeometryReader. The best thing about GeometryReader is that it updates the values as you change your screen orientation and device size, which is perfect for adapting your layout.
You can present the built-in modal animation on top of your current view by using a single modifier, the .sheet modifier.
Often times, you want to use an image from the Internet in your application. However, in SwiftUI you can’t directly use the Image View with a custom URL. Downloading images from the Internet requires asynchronous downloading and caching, and is quite complex.
Fortunately, there are a lot of built-in packages that deal with downloading and caching images for you, like Kingfisher or SDWebImageSwiftUI. In this article, we will focus on SDWebImageSwiftUI. It is a library built just for SwiftUI and is based on SDWebImage.
If you want to show a custom modal in your application, and don’t want to use the default .sheet modifier, you can easily create an onTapOutside listener to dismiss your modal.
Iterating over an array of items is very common when coding. In this article, let’s look at how we can iterate over an array in a View, as well as iterate over an array in a function.
A switch statement listens to a variable x and executes some code depending on the value of x. The switch statement is best used when you have to deal with multiple cases and don’t want to use and if/else statement.
In this tutorial, How do we format a date as [weekday], [month] [day], as in the image below?
When creating an application with authentication, it is essential to cache your user’s data. Even when the user quits the app, the data should still be there for the next time the user launches the app. We don’t want to ask the user to sign in every time they open the app, as that would be bad user experience.
UserDefaults is a class that does just that. It persistently caches the user’s preferences (the currency the user prefers for a store app, for example) as well as any other data you would want (the user’s ID, their email, etc.). It works as key-value pairs and is very simple to implement.
SwiftUI doesn’t come with a built-in method to dismiss the keyboard in your application when the user taps outside of the keyboard area. Fortunately, it’s pretty easy to implement and only requires a few lines of code.
If you want to integrate a video or an audio player in your application, AVPlayer is the way to go. It’s easy and fast to implement, and provides all the necessary tools for you to manage the video.
AVPlayer comes with multiple built-in controls so you can control how your video is shown to the user. Learn how to set up an AVPlayer in your SwiftUI application by reading the Videos with AVPlayer section.
If you want to add a link to a Text in SwiftUI, you’ll need to call the .onTapGesture modifier as well as UIApplication.shared.open.
Showing a share sheet in your SwiftUI application requires only a few lines of code and is so easy to implement.
In any programming language, a string is a data type and is basically a series of characters. Let’s learn about Strings in Swift.