Category: Development (page 1 of 14)

Making your iOS App embrace the iPhone X notch

After yesterdays announcement I decided I’d rebuild RxCalc with the iOS 11 SDK. I figured things would rebuild and my app would fully embrace the new iPhone X without change, but it didn’t work. When I built the app it ran in what I’d call letter boxed mode. The top and bottom were cropped. It was like running an older app on iOS 7, if you’ve ever seen that.

UGH! Why you letterboxed bro?

UGH! Why you letterboxed bro?

I was puzzled. I tried all kinds of jiggery-pokery and nothing worked. So I finally did what any self respecting lazy developer would do. I asked Twitter for help, and Jeff Johnson saved the day.

I was — quite honestly — surprised something so little could make it work, but darn it, you gotta trust the experts. I added a new launch screen at the recommended 1125×2436 size and it worked! Yippee!

Hey, that worked!

Hey, that worked!

So, thanks Jeff! Also, if you’re looking for a bonafide Mac and iOS Developer you should consider reaching out to Jeff — he’s available for work — and has a history of shipping great Mac and iOS Software.

And remember — EMBRACE THE NOTCH!

Work Note: Loading View Controllers from a Storyboard

When I need to load a view controller from a Storyboard I like to create an extension to the view controller’s class and add a class function to it that does the work. It keeps things looking clean in the code where you use it.

I’m not sure if this is smart or dumb. I’m sure very smart people will let me know. Here’s an example.

Here’s how you’d use it in your code.

Old Apps

A cute little monkey.I got an email from Apple a week or so back letting me know I needed to upgrade one of my apps to 64-bit. I knew right away it was Arrgly but wasn’t really sure if I wanted to update it.

On Sunday morning I received an email from an Arrgly user asking if I was going to update it because he likes the app. It felt good to know someone else found my goofy app useful. I decided at a minimum I’d publish a little framework someone else could use to write their own version of the app if I couldn’t get to it, or couldn’t finish it on time.

It took less than an hour to create the project and get it published. If you’re doing Mac or iOS development and you need to shorten or expand URL’s for a YOURLS based service you’re welcome to use YOURLSKit. It’s all Swift 3 but should be fine with Swift 4 projects and iOS 11 or macOS High Sierra. It’s a tiny bit of code, but it does the job.

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

Work Note: Crash at Startup loading libswiftCore.dylib

Future self. If you run into this error when trying to run a build.

dyld: Library not loaded: @rpath/libswiftCore.dylib

Do a Project > Clean, then rebuild. Worked this time around.

Older posts

© 2017 Rob Fahrni

Theme by Anders NorenUp ↑