Using iOS Notifications, Cryptography and iCloud to build your own Chat App XII

I should start this article with a disclaimer, it based on iOS 13, Swift 5 and Xcode 11.x. If you reading this and those numbers look dated, be forewarned.

I should also warn you that notifications and iCloud code, involve Apple’s infrastructure which means you will need an Apple Developers account to use them.

Obviously this is part XI. It is an ongoing series in which I blogging the development of whatsapp type app using the above tech. To get the most of it you need to start at the beginning.

We just added a content extension, which I feel worked well. But I am uneasy about the secret, having a random 8 digit hexedecimal number isn’t too friendly. Lets change the interface so that you can input a secret when you create a user. While we’re at it lets introduce groups as well to make the whole thing more scalable.

Like to say it is a quick minor change, but it isn’t. We need to visit the cloud desktop in our browser and create a new field, group as a String. We need to add a little bit code to out cloud.swift file and we need to do considerable changes to our contentView.swift file.

So, lets get too it. Here is snapshot of the new schema taken from the icloud desktop.

Image for post
Image for post

You can see our new field. Now to the contentView.swift, which has some strategic changes with it. Firstly we need to revamp our data structure. Given the syntax checking in SwiftUI is next to useless, the best way to do this I found is to create a new structure.

Obviously this has a major impact on the main file using it ContentView.swift and of course our cloud.swift file. I made the minimum changes to the cloud.swift for now. Simply rewriting the method that saves my records.

With the changes simply saving the new fields. I have to make changes across the entire ContentView.swift, so I include everything for good measure and then go back and point out the differences.

Yes, it is a monster piece of code. The changes, basically we added two more states at the top. We put in our new references to the icloud code we just changed. And we changed references for the buttons saving and deleting entires. We also changed the pickerview code which needed to reference the new structure. There are a few other minor tweeks in there, but they all revolve around the new data structure.

In the next article we need to revisit the saving() method since it isn’t going to work correctly in all circumstances and we need to think about how we’re going to manage the group instances ultimately.

Written by

Coding for 35+ years, enjoying using and learning Swift/iOS development. Writer @ Better Programming, @The StartUp, @Mac O’Clock, Level Up Coding & More

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