Beginner

Protocol Oriented Programming(POP): A Beginner Guide

Protocol Oriented Programming (POP) is a programming paradigm that emphasizes the use of protocols to define interfaces between components in a software system. It is a popular approach used by Swift developers to build flexible, modular, and reusable code. In…

Refine your OOP skills for iOS Development

Object-oriented programming, or OOP, is a popular programming paradigm that is widely used in iOS development. As an iOS developer, understanding and utilizing the principles of object-oriented programming (OOP) is crucial to building robust and maintainable applications. Whether it’s through…

Show Map in SwiftUI

With SwiftUI, displaying maps in your app is made easy through the use of the Map view. It allows for seamless integration of maps within the rest of your app’s views and gives you control over various aspects such as…

Floating Action Button in SwiftUI

To create a floating button in SwiftUI, you can use a Button with a custom background and a fixed position within a ZStack. Here is an example of how you might do this: This creates a circular button with a…

What should you learn as a beginner iOS Engineer?

As a beginner iOS engineer, there are several key areas you should focus on learning: Overall, as a beginner iOS engineer, it is important to focus on learning the Swift programming language, the iOS frameworks and APIs, the Xcode development…

Drawing paths and custom shapes in SwiftUI

To draw paths and custom shapes in SwiftUI, you can use the Path and Shape types provided by the SwiftUI framework. The Path type represents a geometric path in two-dimensional space, and it consists of a sequence of straight and…

ARC & when to use strong, weak, unowned

Memory management is one of the important concept when it comes to mobile application development. Memory leaks and app crashes are very common due to poorly managed memory in iOS apps. In this short article, I will describe ARC and…

Why should you use private outlets by default?

Access control is very powerful concept in object oriented programming language. Access control helps prevent you from using objects in ways they were not intended to be used. Access control lets you carefully control what properties and methods an entity…

How to detect multiple gestures simultaneously?

If you want to detect multiple gestures at the same time, you can use SwiftUI’s simultaneously function. You can simply say that it is opposite of sequenced gestures described in How to implement sequential gestures using sequenced? For example, this…

How to implement sequential gestures using sequenced?

If you want to collaborate multiple gestures and make them detectable one after another, you can use SwiftUI’s sequenced modifier. To implement combined gestures or sequential gestures you need to create multiple gestures. In this case, the second gesture can…

How to pop or dismiss view programmatically in SwiftUI?

To pop or dismiss the view programmatically in SwiftUI, you can use use @Environment(\.presentationMode) as a variable and call wrappedValue.dismiss(). In the DetailView we have called wrappedValue.dismiss() wen the button is tapped. You can also get the same outcome if…

How to present detail view using NavigationLink in SwiftUI?

NavigationLink helps you to present new view or detail view from the navigation view. While using NavigationLink it pushes the a details view on the navigation stack with built in animation. To demonstrate this, the following code creates a DetailView…

How to show date picker in SwiftUI?

SwiftUI date picker is a very handy built-in modifier(DatePicker) for selecting a specific date, time, or both. A date picker has four modes: date, time, date and time, count down timer. You can display date picker in contact, wheels and…

How to show picker in SwiftUI?

SwiftUI’s dedicated picker can display one or more scrollable items from which you can choose your desired item. It is recommended to use pull-down menu instead of a picker if the list is not very long. A picker typically appears…

How to show a menu in SwiftUI?

SwiftUI menu is a versatile control for presenting a menu of actions. It supports submenus and the primary action from iOS 15. SwiftUI menu is more user friendly and advance than the action sheet. Let’s try a menu named “Manage…

How to show a context menu in SwiftUI?

The context menu provides you access to additional functionality related to onscreen items without cluttering the screen. You can create a context menu using .contextMenu modifier. The context menu is triggered with a long press. Each menu item in the…

How to show an action sheet in SwiftUI?

From iOS 15 you can present an action sheet using confirmationDialog() modifier. In SwiftUI, the action sheet shows a confirmation dialogue using data to produce the dialogue’s content and a localized string key for the title. You need to provide…

How to create background blur in SwiftUI?

Glassmorphism is a very trending UI design paradigm nowadays. We can use the semi-transparent blurry background to give more focus on the foreground content. SwiftUI provides .blur() modifier to create the background blur but it has very limited functionality compared…

How to create horizontal or vertical ScrollView in SwiftUI?

ScrollView in SwiftUI presents its content within the scrollable region. ScrollView can scroll horizontally, vertically, or both. The alignment of the ScrollView is vertical. If you want to make it horizontal then you need to use the horizontal parameter for…

Built-in shapes in SwiftUI

Shapes in SwiftUI are a very innovative, exceptionally simple way to build a user interface component. In this article, we will take a look at simple shapes like rectangle, rounded rectangle, ellipse, circle and capsule. The common use of built-in…

How to show an alert in SwiftUI?

iOS 15 makes the alert presentation a piece of cake. You can show an alert using the alert() modifier. Buttons inside the alert will dismiss the alert view when it is tapped. You can create multiple buttons inside an alert.…

Use of #file, #line, #function when debugging

#file, #line and #function are very common to debug features that are available in other languages like C++. I found it very useful to implement debug/logging manager. We can get the current file name, line number and function name from…

What is given-when-then testing in Swift?

Given-When-Then (GWT) is a structured way to write unit tests. I find it is particularly useful when I need to write complex unit tests. The structure helps me to write and understand unit test faster than the traditional approach. Using this…

What does the associated type mean in Swift 5+?

The associated type in Swift gives a placeholder name to a type that will be used as part of the protocol. When the protocol is conformed, the actual type to use for that it is specified. The associated type makes the protocol generic by…

Grasp mutating function in Swift under three minutes!

The understanding of the mutating function depends on the understanding of reference and value types. In Swift, The properties of value types cannot be changed within its instance methods by default. You need to use a mutating keyword in the…

How to use defer in Swift?

Using defer keyword in Swift code is uncommon. But, It is a very powerful concept for certain use case. The code block inside defer statement is executed just before transferring program control. It does not matter how program control is…

How to use DispatchGroup in Swift?

DispatchGroup allows you to add a set of tasks and schedule them for asynchronous execution. This behaviour can be helpful when progress can’t be made until all of the specified tasks are complete. For instance, If you have several long-running…

Optional methods in protocols

In Swift, If you conform to a protocol you need to implement all its methods or properties. Optional methods are not allowed when implementing protocols. For instance: We can try some tricks to make the optional methods. Use default implementation…

How and when to use typealias in Swift?

The typealias is a simple but powerful concept in Swift. Type alias does not create new types. They simply provide a new name to an existing type. It makes long, compound types easy to manage. In Swift, we are passing…

First-class functions in Swift

First-class functions are the core feature of a functional programming language. Swift isn’t a functional programming language. But, it has the power of first-class functions. In this short article let’s have a look at the first-class functions and their application.…

Map, FlatMap, Filter, Reduce – High order functions in Swift

Higher-order functions are used a lot in functional programming. A higher-order function is a function that takes one or more functions as arguments and returns a function or a value as its result. All other functions are first-order functions. Higher-order…

Use of final keyword in method and class

The Final is a class modifier that prevents it from being inherited or being overridden. While writing an API developer might have a class in the framework that can be abused or misused when subclassed. The solution will be the…

How to use Variadic Parameters in Swift 5+?

A variadic parameter accepts zero or more values of a specified type. When creating API it seems more developer-friendly as we don’t needs to generate an array at the caller site in order to pass multiple arguments. The variadic parameter using three…

When to use computed properties over methods?

I prefer to use computed properties when I need to compose new data from existing data sources or I want to reduce a complicated, nested property name to a more readable and easy to use one (but update it when…