Working with Files on iOS with Swift

Aasif
By Aasif | Last Updated on December 3rd, 2021 10:37 am | 5-min read

You use FileManager to work with files and directories on iOS. It’s a Swift API that helps you read from, and write to, various data and file formats. In this tutorial, you learn how to work with files on iOS with Swift. Here’s what we’ll discuss: How to work with files and directories with FileManager Reading from and writing to text files, plists, images and JSON How to write strings to a file, and read them back Getting a handle on directories your iOS app has access to Workin [...]

Read More

Escaping Closures in Swift Explained

Aasif
By Aasif | Last Updated on December 3rd, 2021 10:37 am | 5-min read

A closure is said to “escape” a function when it’s called after that function returns. In Swift, closures are non-escaping by default. What are escaping closures, anyway? And what do you use @escaping for? Let’s find out! This tutorial discusses closures, escaping vs. non-escaping, capture lists and retain cycles, and what that means for practical iOS development. What we’ll get into: What escaping closures are, and why you need them How and when to use the @escaping keyword [...]

Read More

How To: Pass Data Between Views with SwiftUI

Aasif
By Aasif | Last Updated on December 3rd, 2021 10:36 am | 5-min read

How do you pass data between views in SwiftUI? If you’ve got multiple views in your SwiftUI app, you’re gonna want to share the data from one view with the next. We’re going to discuss 4 approaches to do so in this tutorial! Here’s what we’ll get into: Passing data between views using a property Working with @State and @Binding Passing data via the view’s environment Passing data via @ObservedObject and @StateObject Table of Contents Passing Data between Views with [...]

Read More

Delegation in Swift Explained

Aasif
By Aasif | Last Updated on December 3rd, 2021 10:35 am | 6-min read

Delegation, also known as the Delegate pattern, is frequently used in practical iOS development. It’s a must-have in your iOS developer’s toolbox, and today we’re going to figure out how delegation works. In this tutorial you’ll learn: What delegation is, how it works, and why it’s useful How to work with the delegate protocols in the iOS SDKs Alternatives of the Delegation pattern, and their uses Table of Contents What is Delegation? Delegation: A Simple Example in Sw [...]

Read More

Random Numbers in Swift

Aasif
By Aasif | Last Updated on December 3rd, 2021 10:35 am | 5-min read

Let’s take a look at randomness and random numbers in Swift. Swift has a number of built in functions that help you generate random numbers, with a few caveats though! But first… why would you need random numbers in Swift? In game apps, you use random numbers to simulate dice rolls, or even simulate “chaos” and unpredictability in your games, like random enemy positions or random upgrade spawns In practical iOS development, you use randomness to pick a random item from an array W [...]

Read More

Most Popular Posts