Scripting iOS

Last week Apple acquired automation workflow application Workflow. Of course there was a nice buzz around it and it was a big topic of conversation on various podcasts and websites.

This, of course, got me thinking about automation. I’ve always been a fan of open API’s and the ability to automate applications. We’ve also seen recently that Omni Group is opening up OmniGraffle to automation via JavaScript.

Back in 2010 x-callback-url was created as a way to allow applications to call into each other and return results so you could chain together calls to build custom workflows. Apps like Launch Center Pro and Workflow took advantage of x-callback-url to let you build those workflows and execute them. Now we have a bonafide standard, without a standard. The app ecosystem found a way to support automation without Apple’s help.

I’ve used Launch Center Pro but until recently I’d never used Workflow, and it’s pretty amazing. The Workflow guys did an amazing job creating a drag and drop UI for building what amounts to a program. Well worth a look.

So, this brings me to what I’ve been thinking about over the past few days. Given x-callback-url and App URL schemes in general it would be extremely cool to use those to create object hierarchies using JavaScript. Why JavaScript? Well, it’s native to iOS and applications can use the runtime. Given the advances made by the Workflow team why not take it one step further?

Allow applications to specify a  Scripting Dictionary or Type Library as part of the application bundle, this should allow runtime creation of objects. I know this isn’t rocket science and it’s been done many times over.

Short of adding support to the OS it would be pretty sweet if an App like Workflow, Launch Center Pro, or Pythonista would standardize on a way to parse a URL Scheme into an Object Hierarchy.

I’m going to use Evernote, Bear, Overcast, and Arrgly as examples.

What do you mean by Object Hierarchy?

That’s a good question. Here’s what I’m thinking. Since the Apps mentioned above all support URL Schemes we can derive an Object Hierarchy from them. Basically the beginning of a URI begins with a scheme. The scheme is the name. In the case of Evernote it’s evernote. Pretty simple, right?

Given the scheme name we follow that with a path. In the case of x-callback-url based URL schemes we will skip over that part and move to the second item in the path. This will be the action, or function, or the object we’re going to execute.

evernote://x-callback-url/new-note?type=text&title=EC%203

The above URL will tell Evernote to create a new note of type text with a title of “EC 3”. If we had a way to parse that in a runtime application we could present the user with an Object that has methods that take arguments, like this.

evernote.new-note(type, title)

Let’s do a couple for Bear. First the URL Scheme.

bear://x-callback-url/create?title=My%20Note%20Title&text=First%20line&tags=home,groceries

Now translated into code

bear.create(title, text, tags)

Overcast URL Scheme.

overcast://x-callback-url/add?url=

Code

overcast.add(url)

And finally, my favorite, Arrgly URL Scheme.

arrgly://shorten?url=

Arrgly Code

arrgly.shorten(url)

Pretty simple to turn all of those into objects. When I say you can create a hierarchy it means you could, by convention, lump groups of actions into objects, or like the above examples have a set of actions that all live on a single object.

Here’s what a object might look like as a URL Scheme.

thing://x-callback-url/document/add?title=
thing://x-callback-url/document/delete?id=

That would result in using it like this

thing.document.add(title)
thing.document.delete(id)

Of course this need more fleshing out and it would require app developers to decide on a well known convention to make it work as expected, but it could be done with a bit time and effort. It could be these become an extension of the x-callback-url specification?

MacBook Monster

I listen to a podcast called Accidental Tech Podcast. If you’re a Mac or iOS Developer you’ve probably heard of it or you’ve heard of one or more of its hosts. One of their ongoing topics of conversation is Apple’s apparent lack of focus on the Pro market. It’s true Apple has become very focused on more consumer oriented products, like the iPhone. I mean, who wouldn’t? When you look at the numbers it makes total sense.

When Apple announces results sites like Six Colors do a great job breaking down all the numbers and, in Six Colors case, they make really awesome charts! Just look at this one from January of 2015.

Awesome Six Colors Revenue Chart
Awesome Six Colors Revenue Chart

Who can blame Apple for spending most of their time on the iPhone? Look at those numbers. They’re stunning. It’s not to say the Mac or iPad are losers, they’re not. Most companies would give anything to have one product doing so well, Apple has at least four; iPhone, iPad, Mac, and Watch. Most likely someone will write in to let me know I’ve missed one, or I’m wrong about something, but you get the point. Apple is killing it, on multiple fronts.

What about Pros?

Much of the consternation from the ATP guys revolves around the Mac Pro. Who can blame them? Apple hasn’t shipped a new model since 2013. The hardware is now embarrassingly outdated and is due for a much needed refresh.

As a developer I can understand their need for Phenominal Cosmic Power! But they’re stuck with an Ity Bity Living Space. Not fun.

I’d love to see Apple pull together a great new piece of hardware that includes all the latest, greatest, internals and really appease the Professional Apple Workstation crowd. This would include filmmakers, photographers, designers of all kinds, the CAD folks, and, of course, Software Engineers of all kinds. On my list of nice to haves would be a box large enough to hold multiple multiple core processors (say 256 cores, why not? Windows can do it), tons of RAM, and a killer external bus system to allow folks to chain together external GPU’s. That would be a really great computer, don’t you think? Maybe the base configuration is the most popular, but it sure would be nice to be able to take a Mac and macOS to an extreme level.

Having said all of that, as a Professional Developer I’d prefer a really great Portable Workstation.  What is that? Well, it’s a desktop replacement in a laptop form. Apple is obsessed with making everything thinner and lighter. I do appreciate that, I really do. My first MacBook Pro was a lovely 17-inch beauty, but it was big. Not only heavy, but it was long enough that it was difficult to find a decent backpack to carry it in. Let’s just look at the weight alone, it was 6.6 pounds.

I remember carrying that thing around my first WWDC in 2011. Early morning to late afternoon. Yes, I got tired of carrying it, but it wasn’t a hardship. I would happily trade a bit of weight for a super powerful MacBook Pro.

I read an article recently on the new Dell Precision 5520 on Windows Central. This thing is a beast.

“Besides the big Core processors, all of which are the last generation “Skylake” variants, there is the big kahuna with the Xeon E3-1505M v6. Introduced this year, this Intel Xeon is a quad-core processor with support for ECC memory, 8MB of cache (up from the usual 6MB in a consumer Core i7), and a slightly higher base clock rate of 3.00 GHz with Turbo up to 4.00 GHz. These specs make it one of the fastest mobile processors around, besting the Core i7-7700HQ found in the XPS 15 (9560) by 200MHz.”

Yes, you read that right. This laptop can be configured with a Xeon processor, not to mention 32GB of RAM. That is professional sized horsepower in a small package. This is what I’d like to see from Apple. A true high-end Portable Workstation. Oh, and do you remember the weight of that old 17-inch MacBook Pro I mentioned above? Yes, 6.6 pounds. This Dell weighs 4.56 pounds. Compare that to the new 15-inch MacBook Pro which weighs 4.02 pounds. It’s not that big a difference.

I’d love to have this kind of power wrapped in Apple’s design ascetic. Oh, it should only come in one color. Black.

Work Note: git flow feature start fails

This morning I was creating a new branch to start work on a new feature and I use git flow.

To start a new feature you type…

git flow feature start FeatureName

After typing that and pressing enter git flow complained that it was initialized and I should run the command…

git flow init

I’ve been working in this same environment for two years. I know git flow is configured, but like a good automaton I followed the directions. Of course, you can guess what happened, right? Yep, git flow init says “Hey, you’re good to go!”

I wasn’t. My commands still failed with the same message.

Luckily there is a fix.

Yep, that’s right, cd into the .git directory for that repository and remove all git flow references from your git config file. Then run git flow init. All better.

Apple Professionals Group

A wonderful bouquet of flowers.I wrote down some thoughts a couple weeks back and thought I’d throw them up here. It’s mainly a bunch of questions with some ideas. Unlike a small group of Professionals I don’t need the stuff I talk about here. I’m perfectly happy with my work 2014 MacBook Pro and my 2011 MacBook Pro. Both computers are plenty powerful enough for iOS Development. Here are the thoughts.

Why doesn’t Apple create a Professionals Group dedicated to developing a lineup of serious Pro computers and software? Maybe it moves a bit more slowly than the rest of the company? Maybe you get a computer every two to three years, but it’s at the top of the range, always. Maybe the computers are completely upgradable and modular. Something like we’ve never seen Apple create.

Laptops with “bigger” bodies (think late 2014 15in MacBook Pro), with faster processors and lots of RAM. Maybe you can only get one type of laptop? E.G. 15in MacBook Awesome with the newest Core i7, 32GB RAM, and a 1TB drive, plus a discrete graphics card of some kind driving their already awesome Retina Display.

Think of a more rectangular Mac Pro. One you could open and add RAM, processors, and drives to, easily. Maybe there is a way to plug “modules” into the front and back to the device without cracking the case? Maybe the case is the size of a Mac Mini, but is stackable so you can add additional units Toolbeltthat extend processing power. E.G. pop off a small cover on the top that exposes a slot that the next “Mini” looking device sits right on top of. Oh, how about extending the iMac using these “modules”? That would give us a 5k display and give Pros the ability to scale it up from the base model. Maybe the primary “motherboard” is just a beautifully designed Apple Bus that allows that. Would it be difficult? I’d image it would, but isn’t that what Apple does? They find unique solutions to difficult problems.

Oh, how about creating a professional level display that is also a touchscreen and is on a swivel like the new Microsoft Surface Studio? Why not make it a standalone display that connects to one of these new Mac Pro bases and could also be used with a MacBook Awesome? Super high end stuff.

Apple has billions in the bank. Why not go out on a limb to advance computing down some crazy road with a small group of dedicated hardware, software, and design professionals targeting professionals?

Look. I’m not the ultimate target of such specialized hardware. It would be professionals making movies and dealing with big honking problems. As an iOS Developer I’m fine with a laptop, but I’d sure like to see Apple strike out to create something truly wonderful. Something that changes the computing game, again. This time in the favor of professionals.

Wouldn’t it be cool if they’ve been doing this all along and they just haven’t finished? That would be awesome.

I know this isn’t the type of thing Apple does, but look at what’s possible.

Here’s the Acer Predator line of gaming laptops. Extreme? You bet. But all the same, super powerful portable computers.

How about Project Valerie?

Beloved Hedwig.I’m sure a lot of the loudest of critics would pick these apart: “Oh, they’re too heavy”, “They’re ugly”, blah, blah, blah. Sure on all points. But they’re high performance devices from people thinking outside of the box. They’re not constrained by “Lighter and thinner” at all costs. Imagine what Apple might be able to do if they were willing to make something a bit heavier. Maybe they could so something really special. I don’t think we’ll ever find out. I have a feeling Apple is going to keep making the Mac thinner and lighter until they are so close to the iPad the Mac no longer matters.

Then Apple will stop selling the Mac.

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.

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

The Omni Group and The App Store

The Omni Group: “The app is now a free download. When you first run the app, you’re asked whether you’d like to start a trial or purchase a license. But before you purchase anything, we also explain that discounted pricing is available to existing Mac App Store customers. If you check for discounts, validating your previous install, we either offer you discounted upgrade pricing (50% off) or—for recent purchasers—a completely free upgrade to the new version.”

This is a significant breakthrough. The App Business is a tough nut to crack, especially with millions of competitors in the store. Couple that with the lack of trials and it’s very difficult to keep a business afloat. The Omni Group happens to be a longtime developer of Mac Apps so they know what’s at stake. They create beautifully designed and engineered software at a fair price for Mac and iOS. They’re one of the best in the business.

Until now only really big companies have been able to provide what could be seen as a trial. Microsoft and Adobe are so large they setup subscriptions for their software, think Microsoft Office 365 and Adobe Creative Cloud. While Omni is definitely one of the big players in the Mac and iOS market they’re still a very small company. With this move it finally appears that Apple is relaxing their stance on trials a bit. For productivity software having the ability to use a trial that creates meaningful output and becomes a read-only viewer after a period of time is huge. This will give folks the time to create some drawings, kick the tires, and decide if they really want to purchase OmniGraffle. Brilliant!

Old C++ Code

I was inspired by a recent post by Brent Simmons to write about some ancient C++ code I wrote back in the min-90’s. At that time I was just learning to develop Windows applications in C and C++ was just starting to get some traction, not unlike Swift in the Mac and iOS community today.

When you created a Windows application you’d have to write a WindowProc (Windows Procedure) that would process all messages for a particular window. A Window Proc would receive a message and other parameters. You’d switch on the message and the WPARAM and LPARAM parameters would contain other information specific to a particular message. It was well documented, but it was quite ugly.

Believe it or not this is how a lot of your favorite Windows applications were originally written. Giant switch statements that dissected two other values to determine how to respond to different types of messages.

When I started learning C++ I was trying to find a way to create a Window Proc that didn’t have to implement every Windows message in the system, there must be thousands of them. Could you imagine a base C++ class that responded to every Windows API message in the system? I can’t. It would be a real mess to deal with.

It took me quite a while to come up with a way to do it. I happened upon the answer in the C++ FAQ. This would allow me to create a base class that provided one Window Proc that would look in a dispatch table (a map) to see if the Windows Message was handled by the Window in question.

Here’s what it looked like. I hope this gets the point across.

When you implemented a Window Proc class you would derive from a base class and provide it with a message dispatch table (at the top of the above gist.) The dispatch table would direct the base classes Window Proc to call the correct handler for a specific message.

Notice that this Window Proc is a straight C function. That’s how the Windows API operates. It’s a C based API, but it provides a mechanism to attach user provided data to a Window Procedure. That’s how this operates. When the Windows WM_CREATE message is sent it includes a this pointer to derived Window Class, which can be looked up later based on the HWND identifier.

In the gist above the code that calls pWindow->DispatchMessage knows how to look at the dispatch table and direct the message to the appropriate pointer to a method.

The code that knows how to send a message to a particular method is (this->*pHandler)(wParam, lParam). This is dereferencing a pointer to a method. All methods have the same signature, which is consistent with how the Windows API works.

Will Code C++ for Food
By the way. This code still builds and runs with up to date versions of Visual Studio on Windows 10. A lot of this code was written in 1995 and has been tweaked over time to keep it up to date with changes to the Windows API.

As I’ve said before, old code never dies.

If you’re feeling really brave you’re welcome to grab my crusty old C++ library and build the simple sample application on your Windows box. Please note, the code is provided as is without warranty, expressed or implied.

WWDC 2016

It’s always interesting to read the WWDC tea leaves based on the imagery used on the web site. This year we got a poem and some Swift code.

WWDC 2016 Poem

The Swift in this picture is interesting because we can see they’re calling learnAbout with OSX, not macOS or MacOS as the rumor goes. I suppose they couldn’t give it away even if they were renaming it, could they?

WWDC 2016 Poem

Code is poetry

As much as I’d love to attend I won’t be able to. Dropping somewhere between $3-5K for a conference is tough to justify. I will say it is amazing and I’d love to be there all five days.

At this point I’m hoping to make it to The Talk Show Live once it’s announced, if I can manage to score a ticket.

Maybe I’ll see you there.