How to correctly model data in Swift

Use cases and Implementation

Image for post
Image for post
Photo by @emmamatthews on Unsplash

In this article, we’re going to learn about enumerations in Swift or as they’re more commonly known, enums.

Enumerations are used to model a finite dataset and found commonly in different programming languages. In Swift its history can be traced back to C language but enumerations in Swift are a lot more flexible.

Why Enumerations: the problem

Swift offers multiple ways to model data to be used in a program. We can use object and collections to do that. But there is certain kinds of data where normal objects and collections don’t quite suffice the need. …


A brief introduction to modern-day databases

Image for post
Image for post
Photo by Franki Chamaki on Unsplash

More than seven of the world’s top 10 retailers use Graph databases. Top retailers like eBay and Walmart rely on Graph databases to drive recommendations, promotions, and streamline logistics.

Eight of the top 10 insurance companies, top insurers like die Bayerische, Optum Healthcare, and Allianz, rely on Graph databases to fight fraud and manage information.

Even companies like Facebook and Google have been building their businesses upon some form of Graph database for decades.

Graph databases are powering numerous businesses around the globe and in this article, we will discuss modern-day Graph databases and what led to the evolution of databases. …


From source to destination

Use a self-trained Core ML model for image classification

Image for post
Image for post
Photo by Jacob Schwartz on Unsplash

In a previous article — Build iOS-ready machine learning models using Create ML—we learned how to create and train our own Core ML model using Xcode.

Then, we learned how to fine-tune these custom models to provide accurate results. For that, check out the following tutorial: Create ML — Increasing ML model accuracy.

In this tutorial, we’ll use the model that we created in the previous two tutorials and create an application that will use image classification to classify the food items according to 20 classes that were used for training the data.

The ML model that we have created is a multi-class image classifier. We’ll feed an input image to our model, and the output will be the class to which that image belongs. For example, if we expose an apple to the model, it should correctly predict that it belongs to the class “apple”. …


BUILD ONCE USE EVERYWHERE

Apple’s new state driven declarative UI Framework

Image for post
Image for post

Apple rocked the iOS world with WWDC 2019 when it announced its new state-driven, declarative UI framework. It is a change for the better and in this article we will introduce the framework and touch up on some of its new component primitives.

Before we get started, many of you might be under the dilemma whether to start learning SwiftUI or broaden UIKit’s knowledge. The answer to that question is simple since many current apps still need to support OS versions below iOS13, it is advised to continue growing your horizons on both the fronts.


Creating efficient models

Solving overfitting

Image for post
Image for post
Photo by Pablò on Unsplash

In my previous tutorial—Build iOS-ready machine learning models using Create ML—we discussed how to use our own data and categories to train custom ML models ready for iOS. We used our training dataset (link) to achieve training and validation accuracy of 91% and 89%, respectively.

In this article, we’ll discuss how to increase these accuracy values, how to validate the model using a validation set, and examine overfitting and find a solution to this common machine learning problem.

Validating the model

Since we used only one dataset—i.e. the training dataset—to train the model, Create ML didn’t use all the images in the set to train, since it also requires a set of images for validation (or in other words, training on data the model hasn’t already seen). …


Understanding the basic building blocks in Swift

Anatomy of the Sequence protocol

Image for post
Image for post
Photo by vision webagency on Unsplash

Swift sequences are one of the most fundamental concepts present in the language and we can use it to create custom collection types. The biggest advantage of using sequences as foundation blocks for custom collection types is that we get direct access to highly optimised versions of a bunch of algorithms right out of the box. Since Sequences forms a core foundation block while creating custom collection types, it becomes really important to know Sequences in detail.

In this article we will dive deeper inside the Sequence protocol, discover UnfoldSequence and use it to create our Sequence types with minimal code. …


How to make protocols generic and the advantages of doing so

Image for post
Image for post
Daria Nepriakhina- Unsplash

While discussing generics in Swift, we learned how to make structs, enums, and classes generic.

We discovered how to pass in abstracted type information at the compile time, leaving it up to the compiler to carry that information from compile time to run time. We used protocols to declare the capability of those types.

But what about protocols? How do we make protocols generic and what are the advantages of doing so?

In this article, we will discuss generic protocols or associated types.

Defining a Generic Protocol

Protocols might come across to you as something that is already generic as any type can conform to a protocol, but what about the internals of the protocol? …


Provide intelligence to mobile apps

Use your own data and categories

Image for post
Image for post
Photo by Brooke Lark on Unsplash

Most of the time, when we start working with machine learning, we tend to use models that are readily available online so that we don’t have to spend time and effort creating and training them on our own. But this comes at a cost, as these models don’t usually fit our requirements exactly as expected. Fortunately, Apple has provided Create ML to address those issues, and in this article we’ll learn how to use our own data and categories to train our models.

Intro to Create ML

We can use Create ML to train models to perform tasks like recognizing images, extracting meaning from text, or finding relationships between numerical values. …


Image for post
Image for post
Image source- @travelwithlace

Write reusable code with

Create efficient and reusable abstractions

In this article we will discuss the generics system, use of protocols in generics constraints, @inlinable and more.

We have all worked with simple array examples like the following code a number of times:

var names = [“Eli”, “Adam”, “Simon”]

The code above is exact equivalent of using a variable with explicit type annotation as follows:

var names : [String] = [“Eli”, “Adam”, “Simon”]

and this in turn is a short form for the full generic type…


Provide intelligence to mobile apps

Mobile data sources, ML overview, and basic use cases

Image for post
Image for post
Photo by Jan Tinneberg on Unsplash

In this article, we’ll discuss some foundational concepts in machine learning (ML) that are particularly important for mobile developers interested in working with ML.

Mobile devices provide four different input sources that can be used for machine learning. These sources are:

About

Navdeep Singh

Author of Reactive programming with Swift, Senior Software Engineer — Exploring possibilities with new Tech.

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