Sorting on collection is very easy for single criteria. Swift already has a built-in function for that called sorted (Its in-place variant, called sort). But, sometimes we need to sort the collection by multiple properties or criteria.

To understand this, let’s create a simple struct for Student with the roll number, name, address, and age property.

In order to sort the student list by address we can use the following code:

Student.students.sorted {
return $0.address < $1.address
}

But what happens when the address value will be the same? That’s where multiple criteria sorting comes into the picture.

Multiple…


In Swift (or most of the programming language), the default method for sorting an array uses lexicographic order. That means string Foo12 does come before the string Foo2.

Lexical Sorting

In most cases, we perform lexical sorting on our array. But there might be a scenario where we need to use natural sorting for a better look on for end-user. (eg. Sorting File Names). In the natural soring order, the string Foo12 comes after the string Foo2.

We can achieve natural sorting in swift using the localizedStandardCompare(_:) method from the Foundation framework.


Swift — OptionSet Type

In this article, we will learn what is OptionSet in Swift and how to create your own custom OptionSet.

What is OptionSet?

  • In Swift, OptionSet is a protocol to represent bitset types, where individual bits represent members of a set.
  • OptionSet is similar to enum, but they are designed to work as a set so we can use multiple values at the same time.
  • As OptionSet confirms to SetAlgebra protocol, we can use methods like intersection, union, contains, isDisjoint and several other methods that you might have used on Set.

As a matter of fact, Swift’s OptionSet protocol is the bridged version of…


Easily turn your code into a Swift Package

Photo by Emile Guillemot on Unsplash

What is Swift Package Manager (aka SwiftPM or SPM)?

  • The SwiftPM is a tool for managing the distribution of Swift code just like CocoaPods and Carthage.
  • It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.
  • The SwiftPM is included in Swift 3.0 and above enables us to manage Swift dependencies.
  • With the release of Swift 5 and Xcode 11, SwiftPM support added within Xcode itself.

Here’s a step by step guide for creating your first swift package in Xcode.


Recently, I have updated my Xcode to the latest version (Version 12.2 (12B45b), and my project running fine for real devices. But when I try to run on iOS Simulator I am getting the following error.

building for iOS Simulator, but linking in object file built for iOS, file for architecture arm64

To solve this problem we have to exclude arm64 for simulator architecture both from your project and the pod target.

Solution using Exclude Architectures

  • Open your project in Xcode 12 and click on the targets
  • Navigate to Build Settings of your project.
  • Add Any iOS Simulator SDK with value arm64 inside Excluded…


Migrate your Swift project from CocoaPods to SPM
  • We’re using Cocoapods for several years, but Swift Package Manager (SPM) is new standard dependency manager which included in Swift 3.0 and above. If you are the one who wants to adopt SwiftPM in your swift project, this is how to do it right.
  • Before removing CocoaPods from your project, make sure all your dependencies are compatible with SwiftPM.
  • I’ve found one small tool spmready by Humi to check If all your dependencies are ready to migrate to SwiftPM or not.
  • If all your libraries are not compatible with SPM , then either you go ahead with CocoaPods + SPM


While developing mobile apps that require internet connectivity, it's significant to handle poor network conditions. Because mobile app users will likely to have a much slower network than we use while developing.

As a developer, you didn’t want to throw away your invaluable time looking for a location with a poor network to test the app. So there are some ways to simulate poor network conditions during development.

Simulate Poor Network on iOS Simulator

Apple’s official tool to simulate network connections on macOS for testing purposes is the Network Link Conditioner.

  • Open Xcode and go to XcodeOpen Developer ToolMore Developer Tools...


Achieve pixel perfection on your designs

House plant
House plant
Photo by marra on Unsplash.

Recently, I’ve designed one of the screens of my project using the Sketch application. I’ve given a shadow property to the element with blur and spread.

But when I try to replicate the same shadow effect in the iOS application, it doesn’t quite work. That’s because the spread property does not exist in the CALayer class of the CoreAnimation framework. Also, blur and shadowRadius don't produce the same effect as the Sketch app.

The following are the results of setting a shadow offset of (10, 10) and a blur radius of 10 with spread value of 3 in Sketch and…


During its annual September 15 hardware event on Tuesday, Apple announced the Apple Watch Series 6, Apple Watch SE, iPad Air, and iPad 8th generation. As rumoured before, Apple didn’t debut the iPhone 12 lineup at its September 15 event.

In addition to the hardware products, the company also announced a new subscription service, called Apple Fitness+, as well as Apple One service bundles to help keep things simple — and keep you subscribing.

Apple Watch Series 6

  • The next-generation model has the same design as the Series 4 and Series 5 but features improved internals and new finishes — including the blood oxygen…


In my previous article, we have learned how to integrate SwiftLint into the Project. In this article, we’ll learn how to disable rules. Rules can be disabled either at the project level or source level.

Option 1: Disable Rules at Project Level:

If you don’t want to use the specific rule(s) for your project then you can disable those rules completely by configuring .swiftlint.yml file as below:

# rule identifiers turned on by default to exclude from running
disabled_rules:
- trailing_whitespace
- force_cast
- force_unwrapping
- force_try

It is also possible to skip some files by configuring .swiftlint.yml file as below:

excluded: - file1 - file2 …

Milan Panchal

iOS Team Lead — Mobile App Developer ǁ Swift ǁ Objective-C ǁ Lifelong Learner ǁ Blogger https://milanpanchal.github.io/

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