Swift | Open source projects for learning and developers to follow on twitter

Screen Shot 2018-10-05 at 10.26.35 AM

Announced in 2014, the Swift programming language has quickly become one of the fastest growing languages in history. Swift makes it easy to write software that is incredibly fast and safe by design.

Blog for developers to highlight, top 10 trending open source to learn.

  1. MessageViewController A SlackViewController replacement written in Swift, compatible with iPhone X, iOS12. Created by Ryan Nystrom
  2. Swift interpreter for Pascal language (Inspired from Ruslan’s Blog). Created by Igor Kulman
  3. CollectionViewSlantedLayout subclass of the UICollectionViewLayout allowing the display of slanted cells in a UICollectionView.Created by Yassir Barchi
  4. Mint Package manager that installs and runs Swift command line tools, created by Yonas Kolb
  5. CryptoSwift Collection of standard and secure cryptographic algorithms implemented in Swift. Created by Marcin Krzyzanowski
  6. CocoaDebug Debugger tools for iOS supports Swift and Objective C, created by CocoaDebug
  7. iOS-Depth-Sampler Examples of Depth APIs in iOS, created by Shuichi Tsutsumi
  8. Universal Link Testing  It fetches and parses apple-app-site-association file for you to quickly check whether Universal Links are working. created by Ethan Huang
  9. Swift Syntax Set of Swift bindings for the libSyntax library. It allows for Swift tools to parse, inspect, generate, and transform Swift source code. Created by Apple
  10. WhatsNewKit Showcase your awesome new app features, Created by Sven Tiigi


Thanks for reading!

The table of two values, Behaviour and Structure!

The table of two values, Behaviour and Structure!

Is it more important for the software system to work or is it more important to be easy to change? If you ask the business managers they will say work is more important, some developers also go along with this attitude but that’s the wrong attitude.

Why the wrong attitude?

  1. If you give me a program that works perfectly but impossible to change, it means it won’t work when the requirements change.
  2. If you give me a program that does not work but easy to change, it means I can make the change to make it work.

If you’re a programmer with the attitude (1.) then one day your system will reach to the point where the change will be impractical (cost of change will be unaffordably high).

Eisenhower Matrix

Eisenhower said, I have two kinds of problems, the urgent and the important, where the urgent are not important and the important is never urgent.

when it comes to software, The first value of software is behavior, is urgent but not always important. The second value is architecture, is important but never urgent. Of course, some things are not urgent and not important.

  1. Urgent and important
  2. Not urgent and important
  3. Urgent and not important
  4. Not urgent and not important.

Screen Shot 2018-09-24 at 9.51.23 PM

Mistakes that business managers and developer make is to elevate items in position 3 to 1. It means they always fail to separate those features that are urgent but not important from those features that are really urgent and important and this failure leads to ignoring the important architecture of the system in favor of the unimportant features of the system.

So if you are a software developer, you are hired to maintain the quality and structure of the system and only you know the importance of the architecture.

Thanks for reading it, if you want to read in more detail, buy “Clean Architecture by Robert C. Martin”


Swift Keynotes: classes & structs

  • Structs are the value type.

Screen Shot 2018-07-16 at 4.52.45 PM.png

  • Classes are the reference type.

Screen Shot 2018-07-16 at 4.51.19 PM.png

  • Properties of a constant instance of the struct are immutable because struct’s instance own the whole object and by declaring it as a constant means the whole object itself will be immutable.

Screen Shot 2018-07-16 at 4.59.08 PM.png

  • Properties of a constant instance of the class are mutable as class’s instance owns the object’s reference thus by declaring it as a constant only means that the further reference assignment can’t be done.

Screen Shot 2018-07-16 at 5.01.29 PM.png

  • Structs are blessed with default member-wise initializer but classes are not.

Screen Shot 2018-07-16 at 4.02.52 PM.png

  • Structs are preferable when they are small and copyable.
  • With Structs, there is much less need to worry about memory leaks or multiple threads racing to access/modify a single instance of a variable.
  • Since struct instances are allocated on the stack, and class instances are allocated on the heap, structs can sometimes be drastically faster (but it still depends on how many values you’re storing and the size/structure.)
  • In a multi-threaded environment, for instance, with a database connection that’s opened in a different thread, structs are safer. They can be copied from one thread to another thread, without running the risk of a race condition or deadlock. Classes do not have this inherent safety unless they’re deliberately made thread-safe.

Thanks a lot for reading it.

Introduction | Data Structure and Algorithms | Quick Notes | Back to Old days

Variable: A variable is nothing but a box with a label(its name) and a predefined type promise that you cannot be broken later. Have a look at mathematical equation below. 

X + 2Y = 45

Here, the names X and Y are placeholders for some data that can justify the equation if put in their places. Similarly, in computer science programming we need something to hold data and variables are nothing but that.

Data Types: In the above example, X and Y can hold any type of value such as an Integer value(5, 10) or real value(2.0, 5.8). But to solve this equation, we have to relate them to a particular kind of value they can take and Data Type is that name used for this purpose in computer science.  Or “A data type is a set of data with predefined values used to declare variables/objects. Example: integer, float, double, character, string etc.”

In computer memory, everything is either 0 or 1. A data type is a thing that tells the compiler about what kind of values a particular set of bytes are of and depending on that the compiler takes further decisions on them.

A data type can be a predefined one or can be customized according to the need. Based on this definition criteria they fall into two categories.

    1. System-defined data types(Primitive data types): As their name specifies, they are defined by the system. The primitive data type provided by many programming languages are int, float, double, char, bool etc. The number of bits allocated for each primitive data type depends on the programming language using, the compiler, and the operating system. For the same primitive type, different programming languages may use different sizes and thus their domain(total available values) will also get change. For example, int may take 2 or 4 bytes. If it is of 2 bytes then it’s domain will be -215 to 215-1 and if 4 bytes then the domain will be -232 to 232-1.
  1. User-defined data types: If primitive data types are not enough, we can define our own data type fulfilling all our requirements. Classes are the best example of user-defined data types that most of the programming languages provide. Swift provides class, struct, enum and protocol, four kinds of user-defined data types.

Data Structure: Data Structure is an arrangement of data in such a way that they can be efficiently stored and retrieved. Or we can say that it is a special kind of format for organizing data. The general data structure includes Stack, Queue, Linked List, Tree, Graphs and so on.

Depending upon the organization of data elements Data Structures are classified into two types

  1. Linear Data Structure: Linked List, Stack, and Queue are linear data structures as elements are arranged in a linear manner in them.
  2. Non-Linear Data Structure: Tree and Graph are non-linear data structure as elements are stored in a non-linear manner in them.

We talk about Data Structures as an Abstract Model and their Concrete Implementation.

An Abstract Data Type is a logical and mathematical model defining some set of rules that have to be followed and some list of operations that have to be implemented by the concrete implementation of that model. We can think of ADT as a black box which hides the inner structure and design of a data type.

For example, an Abstract model of a Car can be… an object having four wheels, a steering, brake, accelerator, motor, some number of seats etc. etc. with on/off, run and some other operations.

A concrete implementation of an abstract model is called Concrete Data Type. For example, Duster is a concrete implementation of abstract model Car.

A list, Stack, Queue, Tree, Graphs etc. are abstract data types having some logical set of rules and operations that have to be defined by their concrete implementation regardlessly of which programming language is getting used. In Java, inside java.util package there is a “List” interface which is nothing but an abstract model of List Data Structure whereas, ArrayList and LinkedList are two concrete implementations of List ADT.

Algorithm: An algorithm is a step by step unambiguous instructions to solve a given problem. There are two main criteria for judging the merits of an algorithm.

  1. Correctness: Is it solving the problem in a finite number of steps. Correction can be measured by comparing the expected and resulted output.
  2. Efficiency: How much resources does it take to solve the complete problem?

Algorithm Analysis: Algorithm analysis is nothing but finding the complexity(time and space usage) of an algorithm in terms of input size, being machine independent and considering just basic computer steps. It is the only way to find out the efficiency of an algorithm so that it can be compared with others to choose the best. Complexity is considered in terms of processing time(Rate of growth), memory usage, developer efforts etc.

The rate of growth is a function which defines at what rate the running time increases as the input size increases. Let’s take an example, Suppose in a party, one guest consumes 2 bottles of water. The number of water bottles needed will be, twice the number of guests will come. Here the rate of growth of water bottle consumption is 2n, where n is the number of guests. Rate of growth function f(n) can be defined as  f(n) = 2n.

Why  Algorithm Analysis: There may so many ways to solve a particular problem. But we need the most efficient solution out of all and to get which solution is most efficient, the analysis is needed.

Types of analysis: From algorithm analysis, we basically want to know that with which input the one algorithm takes the least time and with which it takes the longest time. Based on algorithm’s measurement is divided into following 3 types.

  • Worst case: Defines the input for which the algorithm takes a long time.
  • Best case: Defines the input for which the algorithm takes a least time.
  • Average case: Defines the input for which the algorithm takes less than longer time but more than the last time.

Let’s say there are two packets of goodies.
One packet has between 10 and 20 goodies in it (we’ll call this Packet A).
One packet has between 30 and 40 goodies in it (we’ll call this Packet B).
You can pick only one of them but you don’t know which packet is Packet A or which packet is Packet B.

Here, for you, the worst case will be, if you choose Packet A and the best case will be if you choose Packet B.

Asymptotic Notation: Asymptotic notation is kind of syntax or units that are used to express the best, worst and average cases of an algorithm.

  1. Big-O Notation(Upper Bound Function): This notation represents the upper bound of an algorithm which means in any case running time will not be more than this.

In General, Big-O is used to represent the worst-case efficiency of an algorithm where lower bound is not considered. It is represented as f(n) = O(g(n)) where, g(n) is the function which represents the upper bound of f(n).

   General Rule of Big-O notation:

  • Ignore Constants: Example, the upper bound of 4n is n.
  • Ignore lower order terms: Example, g(n)  of function f(n) = n2 + 2n will be n2 (or any value bigger than this), as n2 will be contributing more than 2n for reaching the worst case.

Screen Shot 2018-06-10 at 8.34.30 PM.png

In simple words, we have a complex function f(n) and a simple function g(n) and we want to find a constant c such as, when multiplied with g(n), the resultant value will always be greater than f(n) from some point n0 for all n>n0.

Question: Find Big-O of  f(n) = n2 + 5.

Note: n2 is the upper bound(contributing the most in rate of growth) of this equation. Let’s take g(n) = n2, but to prove f(n) = O(n2) we need to have some positive integer c and n0 which can satisfy  f(n) <= c*g(n). we can substitute any value of c that satisfy the condition. So, let’s put c = 2(or more than 2 will also be fine).

n2+5 <= c*n2

n2+5 <= 2n2

5 <= n²

Hence found, g(n) = n2 and Big-O of f(n) with c = 2 and n0 = 3.

Note: there can be any number of combination of c and n0. And if n2 is upper bounding f(n) then any value greater than n2 such as n3, n4  will also upper bound f(n) thus, they can also be big O of f(n) but we should always consider the tighter upper bound.

  1. Omega-𝛀 Notation(Lower Bound Function): This notation represents the lower bound of an algorithm which means, in any case, the running time can never be less than this. Generally, it is represented as f(n) = 𝛀(g(n)) where, g(n) is lower bound of f(n).

Here, we have a complex function f(n) and a simple function g(n) and we want to find a constant c such as, when multiplied with g(n), will lower bound the function f(n) from some point n0 for all n>n0. we can say f(n) ∈ 𝛀(g(n)) if there exists c>0 and n0 >0 such that f(n) = n0.

Screen Shot 2018-06-10 at 8.34.54 PM.png

Question: Find Big-𝛀 of  f(n) = n + 5.

Let’s assume g(n) = n and prove f(n) = 𝛀(g(n)) by satisfying, f(n) >= c*g(n) for some c > 0, n0>0 and n>=n0 .

n + 5 >= c*n

Here, we can substitute any value of c that satisfy the condition. But looks like 1 is the only value which can satisfy this.

n + 5 >= n

Hence found, g(n) = n and Big- 𝛀 of f(n) with c = 1 and n0 = 1 for all n > 1.

Notice: there can be any combination of c and n0. And if n is lower bounding f(n) then any value less than n such as logn, log(logn)  will also lower bound f(n) thus, they can also be big 𝛀 of f(n).

  1. Big-𝚹 Notation(Average Function): This notation represents the average time that can be taken by an algorithm. Generally, it is represented as f(n) = 𝚹(g(n)) where, O(g(n)) >= f(n) >= 𝛀(g(n)).

Screen Shot 2018-06-10 at 8.35.33 PM.png

Big-𝚹 notation defined as 𝚹(g(n)) = { f(n): there exist positive numbers c1, c2 and n0 such that  c1*g(n) >= f(n) >= c2*g(n) for all n>= n0}. Or in simple words, we have a complex function f(n) and a simple function g(n) and we want to find a constant c1 and c2 such as, when multiplied with g(n), will middle bound the function f(n) for all value for n >= n0.

Question: Find Big-𝚹 of  f(n) = n2 + 5.

Let’s assume g(n) = n2 and prove f(n) = 𝚹(g(n)) by satisfying, c1*g(n) >= f(n) >= c2*g(n) for some c1,c2 and n0 > 0 for all n>= n0

c1n2 >= n2 + 5 >= c2n2

Here, we can substitute any value of c1 and c2 which satisfies the equation. C1 = 5, c2= 1 and n0= 1 satisfying the equation.

Hence found, g(n) = n2 and Big-𝚹  of f(n) with C1 = 5, c2= 1 and n0 = 1 for all n>1.
In General, worst case is considered to tell the efficiency of an algorithm and Big-O is one used to represent that. Big-𝚹 is considered only when the Big-O and Big-𝛀 of an algorithm are same.


That’s all about the introduction of Data Structure and Algorithm but stay connected for next chapter “Linked List”. Happy Learning!! 🙂 

WWDC 2018 | Keynote |Quick Notes | 2 mins

Screen Shot 2018-06-06 at 9.55.14 AM.png

“Today is all about Software,” Apple CEO Tim said as he took the stage at WWDC 2018.

It all started with statistics.

  • 20 million iOS developers
  • 500 million weekly app store visits
  • 81% using iOS 11 where only 8% using latest Android
  • Developers earned 100 million through App Store


Screen Shot 2018-06-06 at 9.50.17 AM.png


  • New iOS 12 will be released as a free update, every model back to the 5S will get a performance boost.
  • ARKit, second generation, which included a lot of cool updates, most interesting is the ability for multiple users to observe and interact with the same environment from different angles.
  • Apple Screen time, now iOS 12 will tell you how much time you’re spending with your iPhone and which are the apps.
  • Do not disturb a lot of improvements, while you are sleeping will hide the notification, one step one time notifications.
  • Photos, with iOS 12 they have revamped it. Allowing more search options driven by AI, share the photos through iMessage.
  • Siri, it’s handling 10 billion requests per month and now Apple is allowing you to interact with it more, create shortcuts to trigger app features.
  • Animojis, more personal now. It’s super accurate, face-tracking and tongue tracking capabilities. Surely it will feel you very familiar.
  • Group FaceTime, now chat with 32 people at once with emoji, sticker, and other effects support.

iOS Apps updates

  • Stocks, new UI with better performance
  • Apple News app.
  • Apple iBooks getting a redesign and a new name.
  • Voice Memos, iPad getting it for the first time and recording will be now synced to iCloud.


Screen Shot 2018-06-06 at 9.51.04 AM.png


So far biggest functions of the Apple iWatch is fitness, now Apple adding more components which let you challenge your friends.

  • Automatic workout detection using your heart-beats(once you stop working out your heart rate decreases, so it will automatically stop).
  • Walkie-Talkie, Texting/phone are tough using watch screen so Apple added an instant audio messaging app called walkie-talkie (uses the wifi or cellular to interact with other devices).
  • Siri on Watch, allow third-party apps to show you more information. Now just lift your wrist and start talking it means no more “Hey Siri”.
  • Podcasts app is coming on your wrist.


Benefits of Storyboards | iOS

Lots of developers consulted with me regarding on how to use storyboard with too many team members like when you have 20 developers on your team? So I have collected my thoughts on that today. I have used Storyboard as well as XIB so here are my thoughts on both.

  • Storyboards are the really nice way to see complete application flow without running into Simulator, you can see the screen flow and the navigation between them, it’s one of key thing that makes your application architecture better.
  • For a larger team of multiple developers it’s really difficult to use the same storyboard because at the end it’s XML file so really very hard to merge and you will end up with a lot of conflicts, So I have noted, a lot of developers suggest XIB here but I don’t see any reason why they choose XIB and I think the best idea is the divide the complete application in different storyboard according to their use-case, that is the first activity I always do, divide complete app into as much as possible storyboard you can (but it’s not like 1 storyboard for 1 ViewController) and use storyboard reference to connect them.
  • I worked in rapid prototype development (deliver the complete application in 15-20 days, developed POC in 7 days) so the biggest benefit that I earned from storyboard is Mock-up, I can create complete app mock-up without writing a single line of code and really easy to manage the transition between views.
  • Few issues that I feel with the storyboard is, it fails at runtime means if you made a mistake with segue name, the class doesn’t exist etc. Yes, it gives issue at compile as well only if you didn’t merge it properly (merge conflicts with XML tags).
  • Using Storyboard, no need to run your app on the different simulator to verify the UI, it gives you fantastic feature called preview (Click on the Assistant editor, select your storyboard, choose automation to preview).
  • Developers say it’s harder to reuse the code in storyboard but my opinion is, first think and implement, try to use mix approach with the storyboard, XIB (wherever requires use XIB to make it reusable on different storyboards).
  • Yes, storyboard creates an issue when you create one in Xcode 8 and try to open it in Xcode 7 but lots of developers already raised this concern with Apple so hopefully, we will hear something from Apple soon.

Thank you for reading! Please do share your thoughts if any.

Creating and Distributing iOS Frameworks | Swift | Tips & Tricks

Why do we need to create frameworks? because it has three major purposes mentioned below and also you can share your code with your team, other developer or iOS community.

  • Code encapsulation
  • Code modularity
  • Code reuse

Let’s create the iOS framework.

Screen Shot 2018-02-05 at 8.24.50 PM

Now just give some meta-data about your framework like name, organization, identifier etc (I hope you’re already aware of it).

Screen Shot 2018-02-05 at 8.26.54 PM.png

We’re good to go till now. Just add the files that you want to keep within your framework.


Build the framework project to make sure that you get build succeeded with no build warnings or errors.

Things that you need to take care.

  • Make sure to check Copy items if needed, so that the files actually copy into the new project instead of just adding a reference. Frameworks need their own code, not references, to be independent.
  • Double-check that each of the files has Target Membership in ThreeRingControl to make sure they appear in the final framework. You can see this in the File Inspector for each file.
  • Double-check the access modifiers, while creating framework access modifiers plays very important roles.
  • if you’re creating Swift framework make sure you’re extending classes from NSObject otherwise it won’t reflect once you will import the framework.

Thanks for reading.

Clean Code | TDD | Swift | iOS | Quick Notes

TDD is a way of writing software, where we write as little code as possible to make the test pass and then late refactor the code.

Golden laws from Uncle Bob

  • You may not write production code until you have written a failing unit test.
  • You may not write more of a unit test that is sufficient to fail and not comping is failing.
  • You may not write more production code that is sufficient to pass the currently failing test.

Whenever we create a new iOS app, we start with UI/ViewController/Business Login directly but Idea here is to start with the Test-cases. How? Let’s say you want to add the functionality to find out the divisible or not as below mentioned the code. Write down the test-case first.

func testIsDivisibleByThree() {
let brain = Brain()  
let result = brain.isDivisibleByFive(number: 5)
XCTAssertEqual(result, true)

But we don’t have the class Brain till now!!! So create a class adds the function, don’t forget the aim is to write as minimum code as you can.

class Brain {
    func isDivisibleByThree(number: Int) -> Bool {
        return true

Because as of now, we are returning static boolean value, test-case will be a pass for sure. Same pattern we need to follow for each and every code we are going to write.

Simple words I can say there are 4 stages in TDD.

RED – Write down the test case
GREEN – Write just enough code to make the test-case pass
REFACTOR – Clean up existing code
REPEAT – repeat the cycle

In above codebase we have done RED and GREEN, let consider the stage 3rd, REFACTOR.

Let’s say now we have to write a function where we need to check whether a number is divisible by given number or not, like this

func isDivisibleBy(divisor: Int, number: Int) -> Bool {
  return number % divisor == 0

So we have refactored the code, Utilizing it like.

func isDivisibleByThree(number: Int) -> Bool {
    return isDivisibleBy(divisor:3, number:number)

the idea is to repeat these steps so we can make sure when we are making any new changes, is it breaking some existing functionality.

I have tried to create short notes on how to follow TDD but also Idea is here is to decouple your code from UIViewController as much as possible so that it will give you more testability scope (for implementing this I have tried MVVM design pattern in few my recent projects, will share one quick notes on that as well).

Thanks for reading.

Clean Code | Quick Notes


A handbook of agile software craftsmanship by Robert C.Martin.

Two reasons for reading this book, you’re a programmer or you want to be. So by the end of this, we’ll know how to write good code because we are going to look code in each and every direction.

There will be a code, some peoples say we are at the end of the code and we don’t need the programmers because business people will generate the program from the specification.  That’s not true because at some level details can’t be ignored so we have to be specified.

It is bad code that brings the company down.

Why do we write the bad code? go fast, in a rush, don’t have to time to think before writing the line of code. One thing we’ve all said we’d go back and clean it up later. But we didn’t know LeBlanc’s Law: Later Equals Never.

The Total Cost of Owning a Mess, we all see teams that were moving fast at the beginning of a project can find themselves moving at a snail’s pace. Every change they make to the code breaks two, three other parts of the code. As the mess builds, the productivity of the team continues to decrease. Now management adds new developer to increase it but it creates the new mess because the new developers are not aware of current architecture and then together they create more mess.

The Grand Redesign in the Sky, eventually team rebels and they inform management that they cannot continue with the codebase and they demand redesign, Management doesn’t want to expend the resources but they can’t deny because productivity is 0. A new tiger team is selected and everyone wants to be on that team, now they have to develop same what old app is doing also the new changes that are coming in. It takes time but after some time, the developers of tiger team is gone and current developers demand new because it’s mess.

Attitude, Why does this happen to code? we complain that the change in requirements, schedules that were too tight, we blame stupid managers, intolerant customers etc. but the fault is in ourselves we are unprofessional.

The only way to make the deadline, the only way to go fast is to make your code clean as much as possible.

What is Clean Code? there are lots of definition given by different deep experience programmers, here I have mentioned one that I like most.

Bjarne Stroustrup, Inventor of C++. I like my code to be elegant and efficient. The logic should be straightforward to make it harder bugs to hide, the dependencies minimal to ease maintenance, error handling complete according to an articulated strategy and performance close to optimal so as not to tempt people to make the code messy with unprincipled optimisations. clean code does one thing well.

Thanks for reading this, here I am also including my point what I like most and I must recommend this book to each and every person who is responsible for writing/reviewing code. For more just buy the book.

STUPID principles | Quick Notes

Recent blog: SOLID vs STUPID

STUPID principles and yes this may hurt your feeling but yes if you are following this you are writing stupid code.


Well known design pattern, but mostly understood one as well. Like me, people are also fighting with Singleton syndrome. In that case, whenever we create a class we create it Singleton but why? That is definability not cool. Singleton also considered anti-patterns. We should think and avoid if possible because the program using Singleton are hard to test because of global state, with the global state they hide their dependencies.

Tight Coupling

Avoiding static things is important to avoid tight coupling. If it’s there then making a change in one module requires to changes another module too. Now it’s really difficult to reuse and difficult to test.


Testing is not hard, what you think? We don’t write test case may be because we don’t have the time or the code we are writing is bad because of tight coupling?

Premature Optimization

One of my favorite quote from Donald Knuth, premature is the root of all evil. There are only cost and no benefits. Actually optimised code is much complex as compared to just writing a loop.

Indescriptive Naming

That’s what I like most and I try to follow as much as possible. Name of your class, variables or methods should be clear because at the end of the day human is only going to read because programming languages are for human not for computers, computers can understand 0 or 1 very well.


That’s bad. Writing same code again and again so don’t repeat yourself, keep it simple and strong. Write Code only once.

Thank you for reading the quick introduction of STUPID principles, next will be SOLID principles.