Categories
Development iOS

Passion Project: Update #2

Back in November I talked a bit about my passion project. I’ve rewritten the Pharmacokinetics Math library for RxCalc in C++ and I’m rewriting the UI completely in Swift. It’s been a real blast. My November update talked about bringing C++ and Swift together with a tiny layer of Objective-C++.

Over my holiday break I didn’t code as much as I wanted to, but I did manage to get some done. Since returning to my day job I’ve felt a bit more excited about working on the RxCalc update at night. I don’t know why, I just have.

I now have the new mixed Swift, Objective-C++, C++ based app in a working state, but I have a lot of polishing to do as well as adding some new features. Of the remaining 1.x features I have to implement is Options. Once that is complete I’ll move on to adding IAP, Theme, and 3D Touch support.

I really love working in Swift. The code base feels so tiny compared to its Objective-C counterpart. Not that Objective-C is bad, just different.

Next up? The Android version. For that I need to spend some quality time with JNI.

I’m not in any shape to ship this release, but it’s getting close by the day.

Categories
Apple Core Labs Design Development Indie iOS Mac Windows

Passion Project: Mixing C++, Objective-C++, and Swift

I know a lot of folks have had to go through the process of bridging to C++ so you can use it from Objective-C or Swift. In my case I’m using it from Swift, so I thought I’d share what the middle Objective-C++ layer looks like. If you’ve done any Objective-C it will look like straight Objective-C, until you look a little closer. That’s when you’ll notice a C++ namespace, new, and delete statement. This code is a straight passthrough to the underlying C++ code — it’s here so Swift code can communicate with the C++ code.

Here’s the code that bridges to our Creatinine Clearance calculation.

You’ll notice a class called PKMConvert that has a class method called genderFromPKMGender. I created a set of mirror enums. One on the iOS side the enums use NS_ENUM syntax, on the C++ side they’re straight C style enums, so this code converts between the two. It’s just a simple mapping.

Another thing you’ll notice is I’m still using “old” C++ syntax to create and destroy objects. I’ve been thinking about updating the syntax to C++11 so I’d use unique_ptr instead. We’ll see if that happens. It’s not a big deal.

Something I’ve been mulling over is releasing the entire PKMath C++ Library as an open source project once I have it working for iOS/Mac, Android, and Windows. I don’t know that it would be overly useful for anyone, but there you go.

Since I haven’t actually written any Swift code in the new RxCalc to use the Objective-C++ code I thought I’d share one of my unit tests for the Creatinine Clearance example above.

Here’s how the different layers look from 30,000 feet. I like pictures, don’t you?rxcalc2layers

Categories
Apple Core Labs Business Indie iOS

Passion Project: Update One

I’ve made a couple runs at the freelance iOS developer life. The first time things went really well, but I was offered a gig by one of my clients and it too good to pass up. A couple years into that position — leading a team developing a Windows video decoding SDK — I got the itch to go back to iOS and the Mac. Around the same time our oldest daughter decided she wanted to move back to California. I took a week off to help move here, and think on this idea of going back out on my own. I decided to give it a go. This time around I failed, miserably.

My attempts to go indie have always been predicated by a desire to develop a product. I thought I could bootstrap my indie life doing freelance work. This was definitely a mistake. Once you start doing client work you’re on that hamster wheel of how do I get my next client? Drumming up work is difficult. I failed at that and I’m also a slow developer. I don’t crank out code quickly, which you need to be an effective freelancer. Get it done so you can move on to the next deal.

When I finally found a full time job I decided I’d work on passion projects and see how that worked out. I’ve had many starts and stops on various projects, but I keep coming back to RxCalc. It was my first iOS app. My brother, Jerry, and I worked on it together. Jerry is a clinical Pharmacist and wanted an iOS app to help him do Pharmacokinetics Calculations. He did all the math and designed the workflow and I turned both into Objective-C. We shipped in June 2009 and RxCalc went live in the store July 4, 2009 (nice bonus.)

I’ve been slowly working on a rewrite of RxCalc. My first iOS app was messy, but it has proven stable — I haven’t had a crash report since the 1.0 release in 2009 — but the code is cringeworthy. I’ve cleaned it a bit over the years as well as shipping a 1.2 release that included some new functionality. That release included much cleaner code, but I’ve wanted to add IAP to it for additional calculation models and port it to Android, and maybe even a Universal Windows App.

When Jerry and I originally started developing what was to become RxCalc it began life as a Palm app in C++ and the Pharmacokinetics math library was portable C++. It built on Palm, Windows, and iOS — it built first time on iOS with zero change. When I was learning Objective-C I decided it would be best to port PKMath from C++ to Objective-C. That was really easy. It didn’t take long at all.

Here we are in 2016 and I decided I’d better get started with my grand plan to make PKMath portable, again, and build for iOS, Android, and Windows. Why? Just because. Remember, this is a passion project. I don’t make any money on RxCalc, but I do have a plan to change that with this new version.

Will write C/C++ for foodThe new C++ PKMath library is written. I’ve built a small layer of Objective-C++ over the top of it so I can write the new UI in Swift. The old RxCalc was 100% Objective-C, the new one will be a mix of C++, Objective-C++, and Swift. That sounds kind of weird, but there is a means to an end.

Android is my next target. I’ve started working on JNI wrappers around the PKMath library. This has proven to be extremely difficult. It’s going to take some time to wrap my brain around how this all works. I’ve managed to write a simple sample that uses PKMath to calculate an Ideal Body Weight and display it in an Android view, but that’s as far as I’ve gotten.

As for Windows it’s the thing I’m most familiar with. I’ve spent most of my 25+ years as a developer building Windows applications. The downside is I’ve never built a Universal Windows App and I’m not sure how to properly build PKMath for it. I’ll figure that one out and I imagine it will be as easy as wrapping C++ in Objective-C++.

Progress is slow and I’m easily distracted. We’ll see how it goes. More updates to come.

P.S. — I find Swift to be the most enjoyable language I’ve ever used. Doing the new RxCalc UI has been a lot of fun.