Now we have our project ready to go. I don’t like using storyboards myself, so the app in this tutorial is built programmatically, which means no buttons or switches to toggle — just pure code 🤗.

To follow this method, you’ll have to delete the main.storyboard and set your SceneDelegate.swift file (Xcode 11 only) like so:

With Xcode 11, you’ll have to change the Info.plist file like so:

You need to delete the “Storyboard Name” in the file, and that’s about it.

Create View Controller

We only need one View Controllers:

ViewController():

This is where we’ll set our UICollectionView with all the text and show the text’s topic.

Create a navigation

MainTabBarController():

This is our main navigation where we’ll create the full navigation structure for our application.

Navigation in iOS is pretty straightforward and easy to implement. Here, I’ve changed some things like the font for the navigation bar, etc. so it looks nice.

Setup a UICollectionView — ViewController.swift

Create and setup the collection’s layout

First, instantiate a UICollectionView object and cellId object:

Then set up the layout and add delegates:

We also need a CollectionViewCell . I’ve created a custom one, but you can obviously use the default one:

Populate the collection view

We need a model to host our text and the prediction, so for the sake of simplicity, I’ve created a struct called “Model”:

We also need to create an array of Models that will be used to populate the UICollectionView :

var cells = [Model]()

Now we have an array of models we can use to populate the collection. I prefer to use extensions, so I’ve created a separate file:

I’ve also added a small extension for the String class so that I can calculate the height of the text and resize the collection view cells dynamically.

Add new text:

We need to setup the tabBar and add a rightBarButtonItem with a ‘plus’ sign button that will allow our users to add text and predict the topic.

This button should also trigger a UIAlertController with a TextField:

Get the inference and populate the CollectionView :

Get the inference

I randomly choose some articles from Google News:

Here’s the result: