Freedom is every creature birthright

Why to rethink ??

Did it worked ?


Sharing my notes that I prepared to remember the python syntax from already known language syntax. (Swift 4.2; Python 3.7)

“The Loci method is one of the most ancient memorization tools known, and is based on attaching individual items you need to remember, to individual points on a route you are familiar with, so you can easily recall the items as you “walk” that route in your mind.”

  • Basics
  • Collection Types
  • Class, Struct
  • Closures
  • Exception Handling
  • Unit Testing

Import Modules

Swift

import Foundation

typealias a module

typealias SMSomeStruct = SomeModule.SomeStruct

Import only parts from a module

import struct­ SomeModule.SomeStruct
import class­ SomeModule.SomeClass
import func…


by mocking URLProtocol

Please check the previous articles on Network Layer Part 1 and Part 2.

What is Mocking?

In object-oriented programming, mock objects are simulated objects that mimic the behavior of real objects in controlled ways. (wiki)

In our case, we have to mimic URLSession so that it will return the mock object without hitting the physical server. We can achieve this by creating MockURLProtocol that confirms to URLProtocol and implementing its required methods. Now our MockURLProtocol is capable of handling the specified request.

MockURLProtocol

Now we have to add our MockURLProtocol to the URLSessionConfiguration.protocolClasses


Writing Unit Test cases Using XCTest framework

In the previous article we discussed about how to write Testable Network layer.

In this article we will discuss about how to write unit tests for that network layer. Basically to perform unit tests, we have to know expected output for the given inputs.

Remember we never actually hit the physical server to run tests, doing so we cannot test all possible cases.

For each APIHandler we have two methods to perform tests as mentioned in Part 1.

func makeRequest(from parameters: [String: Any]) -> Requestfunc parseResponse(data: Data) throws -> LoginResponse

Testing API…


Using Swift Generics & Protocol Extensions to Decouple Network Layer Code

When you write a program, the code should be readable, maintainable and testable, as per coding best practices.

“A code that can not be tested is flawed.”

As iOS mobile app developers, we often write a lot of code that deals with UI, network, persistence and other business logic. In this article, we will share our implementation of Network Layer, which deals with API /web-service interactions, to help to write tests on network layer logic.

Before writing tests, we need to become familiar with how to decouple Network Layer code from UI related code and other business logic. …


We generally maintain service constants in a constants file, changing the endpoints for environments like development, staging and production. Unfortunately, this process is prone to human error when pushing builds to the store or doing an adhoc release. To avoid this, we can construct baseURL per the environments, as shown below.

Then you can add application-related functions in extensions like this:

Kiran Sarella

Software Developer @AppIt Ventures

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