JSON data is not always homogenous. There are instances in which a JSON object field can contain objects containing different information.

In such cases, the Swift type for the decoding must be determined dynamically.
JSON data is rarely flat and often contains nested objects.

Nested JSON data can be decoded in Swift using the `Decodable` protocol and the `JSONDecoder` class.

However, how you decode nested JSON objects depends on the final result you want to obtain.
JSON object with dynamic keys presents a specific challenge when decoding data in Swift because stored properties cannot represent dynamic keys.

However, it’s still possible to decode JSON with dynamic keys using the Decodable protocol into dictionaries or arrays by implementing structures that conform to the CodingKey protocol.
You can easily parse JSON data in Swift by creating a `Decodable` type that matches the structure of a JSON object.

However, we often need to decode JSON data that does not match the model types of our apps. In those cases, we need to control the decoding using coding keys.
Fetching and parsing the JSON data returned by a URL is straightforward in Swift, thanks to the JSONDecoder and URLSession classes of the Foundation framework.
Since Swift 4, the recommended way to parse JSON data is to use the `Codable` protocols with the `JSONEncoder` and `JSONDecoder` classes.

However, this method requires creating Swift model types that match the JSON data structure you need to decode.

Sometimes, you might want to avoid creating extra Swift types if you only need to read some of the information in the JSON data locally.
Apps often need to read the content of JSON files for different reasons.

You can save static JSON data inside an Xcode project to populate your app or use it in SwiftUI previews.

Apps can also save data inside the device’s documents directory.
JSON data is often not human-readable because web servers strip all white space to save bandwidth.

Converting JSON data into a formatted string helps build decodable Swift types and is useful when debugging and testing an app’s code.
The Date type is a Codable type in Swift. However, dates are not straightforward to decode, like other types conforming to the Codable protocol, because the default format used by JSONDecoder is not standard in JSON.

Dates can be encoded using different formats in JSON data. To handle all these formats, the JSONDecoder class has a dateDecodingStrategy property, which can be configured with several decoding strategies according to the date format you must decode.
Becoming an iOS developer is a great career choice that allows you to demand a high salary and work on interesting projects at top companies.

Learning iOS development can take time, but you can speed up the process and optimize your learning following the steps I outline in this article.
You can make a REST API call in Swift in just three lines of code thanks to URLSession and async/await.

However, implementing a networking layer in a full-fledged app presents several architectural pitfalls.

In this article we will see how REST works, how to perform API calls in a SwiftUI app, and the best way to architect the networking layer of an iOS app.
A Swift dictionary stores and access data with logical relationships, holding any number of key-value pairs as long as the keys are unique.
Many modern iOS apps are connected to the internet.

When you need to download or upload data, URLSession is the solution.

Together with other types, URLSession not only transfers data over a network but also groups transfers together.
Conditionals are a fundamental part of programming in Swift.

The first conditional statement you learn is the if statement. It’s not the only one, though, nor is it the most used.

Another example is a guard statement. Guard statements are often much more common than if statements.
URLs are omnipresent in today’s world, and iOS apps are no exception.

The URLs you use in Swift can identify different resources. The most common examples are web content, local files, and REST API endpoints.

The way you handle a URL in Swift depends on two things. The resource it identifies and how you manage the resource in the architecture of your app.
Arrays are the most commonly used data type in Swift and other programming languages. You will often use arrays to organize your app’s data as they are the most versatile data structure.
The easiest way to install Xcode is using the Mac App Store.

But that’s not necessarily the best way.

While you can install Xcode with a simple click, using the Mac App Store is very slow, and the download might hang indefinitely or return cryptic errors.
The ternary operator is a conditional operator that you can use to write complex conditions using just one line of code. It is straightforward to use and powerful.

In this article, I will highlight the most common use cases of the ternary operator in Swift. I will also review the advantages and disadvantages of writing conditions using the ternary operator instead of if-else statements.
Switch statements compare specific values against different cases and execute the block of code associated with the first matching case. You can achieve the same result using an if statement with multiple else clauses, but switch statements are easier to read and understand at a glance.
To be able to do anything interesting, a Swift program needs to take decisions based on whether some condition is true or not. This is done through conditionals.

Swift has several conditionals. The most common one is the if statement, which we will cover in this article.
Learning how to program is not an easy task. But it is straightforward to get started with it by following a very simple Swift tutorial.

The very first program everyone writes is called Hello World. It teaches you the basics of creating and running a program in any language.
Most modern iOS apps need to run code asynchronously.

Asynchronous code can be suspended and resumed later, allowing your app to keep its UI responsive while working on long tasks, like performing network requests to a REST API.

You often run asynchronous code in parallel to make the best use of resources like the cores on your device’s CPU or internet bandwidth.
Any iOS developer, at some point, feels the need to make the step from basic to advanced concepts.
You can get a lot of mileage from the fundamentals of Swift and iOS development.
But working on complex projects demands a new set of tools if you want your code to be reusable and remain at the same time maintainable and testable.
If you are looking to expand your Swift knowledge into more advanced topics and understand why you would need such concepts, this article is for you.
Networking is a requirement for most modern iOS apps. Apps usually interface with a remote web service. And often, such a web service is a REST API that returns JSON data.

Writing the networking layer of an iOS app is not a simple task. When making asynchronous network calls, you need to combine several features of Swift, SwiftUI, and the Foundation framework. Moreover, many parts of your app’s architecture need to interact, making the task more complicated than it might seem at first.
SwiftUI offers several mechanisms to pass data between views.

Such abundance can make it hard to decide which data flow mechanism fits any particular situation.

Those decisions cannot be taken in isolation. As in many other cases, we need to keep an app’s architecture in mind to make the correct choice.
Since the introduction of SwiftUI, the MVVM pattern has seen a new renaissance. Many developers believe that this particular pattern fits well with the SwiftUI data flow.
MVVM certainly has some good ideas, but it also brings along problems because of the various discording interpretations of the pattern and its rigidity.
In this article, we will see how MVVM fits in iOS apps written in SwiftUI, how to take advantage of its benefits, and how to avoid its problems.
Decoding JSON Data is a fundamental part of modern iOS apps. This comprehensive guide covers all the aspects of the Codable protocols in Swift.
Many developers find unit testing confusing. This is made worse by the advanced techniques you need to test classes or asynchronous code, like the one for network requests.

In reality, at the base of unit testing, there are simple fundamental concepts. Once you grasp those, unit testing suddenly becomes more approachable.
Generics are a great feature of Swift that allow you to generalize and reuse code in ways that would not be possible otherwise.

They are also a quite advanced feature and become a roadblock for many developers. The iOS SDK uses generic extensively, something that is especially true in SwiftUI.

In this article, I will show why generics exist and how to use them in your apps.
SwiftUI is a revolutionary way to create user interfaces on iOS and other Apple platforms.

It introduces a new declarative syntax that allows you to build user interfaces packed with features quickly.

In this article, I will show you an overview of the SwiftUI features you will need in every iOS app you will ever build.

Showing the last 30 only...