Holiday Card App Update

Well, it has been three years in the making, and I am finally starting to feel that this app may be ready. I’ve not had much time to work on it over the three years, but I’ve used this app to learn CoreData and CloudKit. On Christmas Day, I finally broke through and fixed my last MAJOR problem with CloudKit.

You see, I’ve been using this app to capture what cards I sent to which person. I’ve been storing the images locally in the app’s Documents folder, but I could not figure out how to easily get this to Sync. So I wanted to move the pictures into CoreData and then use CloudKit to sync the data between devices.

When I first started really working on this part over the US Thanksgiving holiday, I kept having issues where the app and CloudKit would crash. This only happened when I put on my devices, which had three years of card data! The simulator actually worked fine. I ended up learning how to finally use Instruments, and saw that I had two major problems. First was a memory leak. I had used sample code from https://www.raywenderlich.com to become a Transformable data type. What this does is make it so CoreData handles storing data in binary format, but your program just uses the appropriate format for the data. In this case a UIImage. Unfortunately this code didn’t free memory correctly, I fixed this by placing the code in a autoreleasepool{}. This means that when you program moves past that line in the code, it will release the memory allocated during the code. This solved part of the problem – no more crashes!

However, the program still didn’t sync the data. Looking in instruments again, I saw that CloudKit sync was crashing a lot too. I had converted the UIImage to a PNG data type. This is a lossless compressed file format, and as I’ve improved my iPhone over the three years the pictures had ballooned to about 30-40MB each! This is bigger than my first ever hard drive back in the late 80’s. (A 20mb hard drive which held all my programs, games and data at the time, with room to spare!).

So I ended up changing the image to a JPEG, using the least compression it would do, and now I have pictures in the 2-4mb range. Problem solved! All the images for the last three years have synced into CoreData and via CloudKit to my secondary device. Now I just need to wait for the App Store team to get back from vacation, and I will release the app to my Alpha testers!

Progress!