[Recap] Subject

A Subject is both an Observable (emits sequences) and an Observer (Subscriber). You can subscribe to a subject such that the subject acts as an Observable emitting values and also modify the subject.

Types of Subjects

BehaviorRelay, PublishSubject, ReplaySubject, AsyncSubject.

Note: Here we are going to talk about…

Learning Objectives

  1. Display Modal view using sheet
  2. Dismiss Modal view
  3. @Binding property wrapper
  4. Navigate to another view using NavigationLink

In this example the VStack on line 9 has two Views a Text and a Button.

On tapping the button, the action closure on line 13 toggles the State variable showSheetPresented

Why Generics?

Solve the problem of code duplication. Generics can be used to create a Generic data structure like Stack or Queues. Generics can also be used to create Generic functions.

Q: Examples of Generic in Swift Standard Library

Arrays, Dictionary

Generic Data Structure

Examples of two generic data structures (Queue and Stack). Here Element is the placeholder type and Queue<Element> and Stack<Element> — the angled brackets tell the compiler that Element is only a place holder inside the function body and function definition. The actual type of Element is determined only at runtime.

Usage of Generic Stack and Generic Queue

iOS provides two ways to achieve multitasking

  1. NSOperationQueue

2. Grand Central Dispatch (GCD)

GCD Grand Central Dispatch

  • Introduced in iOS4
  • Important concepts are DispatchQueue and DispatchWorkItems

What is a DispatchQueue?

DispatchQueue overview

As the name suggests it is a queue (i.e. First-In-First-Out FIFO). You submit a block of code (closure) or an…

Pascal’s Triangle as known to the western world but I would like to refer it as Meru-prastaar — coming from the vedic land India or Khayyam triangle if you happen to hail from Persia. Nevertheless, it is an interesting arrangement of numbers :)

Pascal’s Triangle

One of the solutions to print the…

What is a Delegate?

  • Allows loose coupling between classes due to using Protocols
  • Allows to hand of responsibility from one class to another
  • The class that offloads the work is the delegating class and the class that does the actual work is the delegate class. …

What is optional chaining?

A way to access the property, method, subscript of an optional in a safe way.

An alternative to “Forced Unwrapping” of an optional.

Use a question mark ? after the name of an optional and then access the property, method, or subscript of that optional.

  1. Optional chaining — how to…

Swift tip #1 Empower the print function using literal expressions

you can use literal expressions to print function names using #function, lines numbers #line and filenames #file

Sample Code

Neeraj Sharma

Mobile application developer, an urban traveller, and a passionate photographer — “programming is a creative process almost like story telling”

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