SwiftUI is a new Toolkit introduced by Apple in WWDC 2019. As per Apple description:-
SwiftUI is an innovative, exceptionally simple way to build user interfaces across all Apple platforms with the power of Swift. Build user interfaces for any Apple device using just one set of tools and APIs.

Today we are gonna understand

  • Why is it needed?
  • Finally, understand a sample code written in SwiftUI

So without delay let’s start our deep-dive into SwiftUI.

What is SwiftUI?

SwiftUI is a toolkit provided by Apple to build a user interface such as Custom Controls, Animations, Effects programmatically in a simple, declarative way. …

Recently I got this interesting problem to solve. To parse a JSON with the content of dynamic type. JSON looked something like this:-

As one can see a value for property content can be an Int or String. In future, there can be different types of content added like Float, Dictionary etc.

In Swift, we use Decodable to parse any JSON to its respective Model. So let’s first create an equivalent Struct for above-mentioned JSON. On my first try, I created something like this:-

So what will be the type of content mentioned in Struct Body?

On my…

Composable Query

Recently I was working on a sample project link. The objective of this project was to consume a list of user feedbacks in a given period of time, derive some information out of it and display it in a meaningful format. What I did was to fetch all the data in a selected range and then find an average rating and number of user who gave that rating over a periodic interval. Then show this information a line chart using iOS Charts library.

This solution seems to be simple and meaningful. But I started seeing a few code smell problem…

In today’s era, we as Software Developer have been in a mode of delivering gobs and gobs of features in shorter sprints. This practice has taken us away from one of our core responsibility as Software Developer that is writing Simpler, Reliable and Anti-Fragile Software. We use “easy” frameworks and tools, without giving the problem due thought. That we confuse easiness, with simplicity.
This blog is a reflection of my thought and understanding about writing simpler code. I went through a few articles and videos about software complexity and how to deal with it. …

In our last session, we have talked about Functional ways to do error handling and looked at how this is a better way to handle errors. To achieve this we introduced some new Data Types like Optional, Try, Either. These are Functional Data Types and they helped to solve Exception/ Error handling issues. Today we will talk about simplifying DI in our app.

What is Dependency Injection?

DI is a concept which makes a class independent of its dependency management. It achieves that by decoupling the usage of an object from its creation. This helps you to follow SOLID’s dependency inversion and single responsibility…

Exception & Async can't go hand in hand

Till now we have been mostly talking about Functional Concept like Composition and Currying with some practical usage. But for a change, I thought to pick a topic which developers encounter in an everyday scenario.

Exceptions in OOP centric languages

Throwing an exception and handling them in a try catch block is something which every developer encounter quite often. But if u forget to handle an exception “all hell breaks loose” at runtime. This becomes one of the most commons reasons for an application to crash in production or become unresponsive. Making your application looks bad.

But Why would I forget to handle an exception?

An excellent question. But a simple answer. Exceptions are…

The concept of functional currying

So from our last session, we learned about Function Composition. Why do we need it? How to do it? How to make composition convenient by removing a lot of boilerplate? So continuing with the same theme of functional programming. The next stop will be at Function Currying.

So today we will try to answer following questions regarding Function Currying:-
1. What is Function Currying?
2. Why do we need function Currying?
3. How to convert a function to curried function?
4. How Function Currying help us in a day to day programming?

With these questions answered, we will be one…

essence of programming

Continuing from our last session on Side-effect we will continue our journey to explore the core concepts of functional programming. The next stop in our journey is at Composition. One of the most important concepts of programming for any kind of programming style.

Today we answer 3 basic questions regarding Composition.
1. What is composition?
2. Why is composition required?
3. How to compose a function?

What is Composition?

Composition is the process of combining two or more smaller components to produce a new larger component. The word component has different meaning in different context. In functional programming, components are…

What are pure functions?

A pure function is

  1. Referential transparency, meaning they consistently yield the same results given the same input, irrespective of where and when they are invoked. That is, function evaluation depends less — ideally, not at all — on the side effects of mutable state.
  2. Produce no side-effects

Advantages of pure functions

  1. Simpler to reason about
  2. Easier to combine
  3. Easier to test
  4. Easier to debug
  5. Easier concurrency

What are side-effects?

Side-effect is some extra work done when calling a function which changes something in the world around it. Lets take an example to understand it better.

Problems with side-effects

  1. Cannot be tested
  2. Cannot be…

Balraj Singh

Software Engineer, Blogger, Tea Lover and Learner

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store