Buttons are an essential element in iOS apps. If you are developing an app using UIKit, you will probably use UIButton class to create buttons.
Creating a button is a straightforward process, but it becomes problematic when it comes to customizations. Soon you will find yourself writing hacks for achieving your…


Deque (should be pronounced as “deck”) is a collection implementing double-ended queues.

Deque (should be pronounced as “deck”) is a collection implementing double-ended queues. Deques are similar to arrays, but they have efficient insertions and removal of elements at the beginning and at the end.

The indexing semantics are integer indices that are the same as arrays. …


Swap keys and values of a Dictionary in Swift

Dictionaries are one of the most commonly used data structures. Dictionaries come with keys and values where the keys are unique. Sometimes, there might be a situation where we would want to swap the keys and values of a dictionary. …


Replacing Selectors with Closures in UIButton

iOS 14.0 brings us many improvements and new APIs using which the developers can write efficient code. One such API is the closure based action API instead of the addTarget method in UIControls. Yes, you heard me right—no more usage of addTarget methods, #selector(), and @objc annotation in front of…


Experimenting with Swift async and await pattern using Xcode

You all might know that async/await is accepted and is available in the main snapshots! Let’s get our hands dirty by trying out some basic example of async/await in Swift.

Prerequisites

  1. Xcode 12.3
  2. Latest Swift Toolchain (You can download it from here)

Installing the Swift Toolchain

Download the Swift Toolchain…


One of the most widely used features in Swift are the optionals. Optionals are types that can hold either a value or a nil value i.e nil.

Consider that there is an array of optional values. Usually, we use if let or guard statement to unwrap the optionals.

//An array…


Boolean is one of the most frequently used and simplest data type in any programming language.

It is common to want to toggle the state of the boolean variable. So, we normally do it like this,

private var isEnabled = trueif isEnabled == true {
isEnabled = false
}


We all would have written a piece of code similar to this,

The usual way,

let items = [1,2,3,4]for item in items {
if(item % 2 == 0){
print(item)
}
}
Result: 2 4

As a Swift developer we always want to write better code. …


Apple released Swift 5.0 development snapshot (toolchain) for the developers to get a taste of the new language. In this article I will explain how to bundle Swift 5.0 toolchain with your Xcode.

As per Apple’s definition, “An Xcode toolchain (.xctoolchain) includes a copy of the compiler, lldb, and other…


When Swift was first introduced, we didn’t know the real potential of the language. It was primarily used for developing iOS and mac applications using Xcode. But when Apple open sourced the language, it opened the doors to many unseen experiments. …

Rizwan Ahmed

iOS Engineer @zoho , Creator — http://ohmyswift.com Support OhMySwift by buying us a pizza! 👉 https://buymeacoffee.com/ohmyswift

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