Use SwiftyJSON to deal with JSON data in Swift
👋 Hi, I'm Javal Nanda, a Mobile Application Developer based in India. I've been in the world of mobile app development since 2010, and this blog is my space to share experiences and thoughts.
Search for a command to run...
👋 Hi, I'm Javal Nanda, a Mobile Application Developer based in India. I've been in the world of mobile app development since 2010, and this blog is my space to share experiences and thoughts.
No comments yet. Be the first to comment.
We often need to modify the SwiftUI view in some way or the other. There are three ways in which we can achieve customization of the SwiftUI View: View Extensions ViewModifiers Custom Views We can almost produce the same results with the above a...

One of the main rules for writing clean code is that it should clearly show what it's meant to do. There are a few things to keep in mind when doing this. It means giving variables and function names that make sense, making sure each part of the code...

Pull requests are the standard way to request a change to be merged into the main or stable branch. Having fellow developers or maintainers review the change is crucial to ensure its quality, although exceptions may apply for teams using pair program...

Ideally, you would not require conditional logic in your production code to check if tests are running or the main app target is running. But, there are situations where you can't get around it in case of Integration tests or UI Tests. There are vari...

If you have used SPM to create the command line application before Swift 5.9.0, the project structure used to be as follows: Package.swift README.md .gitignore Sources/ Sources/SamplePackage/main.swift Tests/ Tests/LinuxMain.swift Tests/SamplePackage...


How many time did you get lost in optional chaining while dealing with JSON data in Swift? The struggle is real and code gets really messy while parsing complex JSON data.
Let us take an example of the following type of JSON data that you might receive from API Call:
Now to access the “title” of the “glossary”, the standard way we would write is:
Or if we do optional chaining it will look messy even if we are just accessing first level element of JSON
Now, let us see how to parse it using SwiftyJSON:
Yeah! no tension of optional unwrapping, simply access it via keys you want and SwiftyJSON takes care of the rest.
And guess what? Even if you access a wrong key by mistake, .string property takes care of safety.
Hence, SwiftyJSON makes our life easier to deal with JSON data compared to the standard way of dealing with it.
To use SwiftyJSON, you can integrate it either via Cocoapods or Carthage.
And finally, there is even an extension to make serializing Alamofire‘s response with SwiftyJSON easily: Alamofire-SwiftyJSON.
Found it useful? Share it with other fellow developers to help them write more swiftier code.