Friday, January 23, 2015

Sizing Subview to Superview Using Autolayout with VFL and Cartography Using Swift

In talking with the Lead Developer of Mitosynth, I got inspired to get deep into Swift, Autolayout, and Cartography. And in the last 24 hours, I've been tearing my hair out with Autolayout in Cocoa using Swift. I finally got it down to a single question on Stackoverflow.

The answer to that question opened my eyes: Cocoa was "automatically adding constraints!" So without further ado, here are all my concepts wrapped up in one. This example uses Autolayout, VFL (using a nice category I made for Swift), and Cartography, too. Whoot!

VFL, Autolayout in Swift

I don't really understand this Visual Format Language (VFL_ stuff, and it rarely does what I want, but if you read the Apple page on it you'll get the idea. Anyway, here's an extension to use them in Swift. Substitute UIView for NSView if you're working on iOS Here is is on SO: link

Wednesday, January 21, 2015

My System: Workflowy for GTD

I can no longer fight it. I use Workflowy for everything. Using an external app for my todo list is just silly (though Wunderlist is awesome). So... here it is:

Never have a task list. Use tags and build out your world wherever you are.
  • Every Node is #project or #task or maybe a #superproject
    • Everything else is somewhere above, below, or in-between. So most of your Workflowy tree is not seen in the searches below
    • In GTD talk, a project is a series of actions needed to produce an outcome
    • In GTD talk, a task is something you can do...
      • Ramble:
        • This could contain other subtasks
        • But these are the things that a project is going to use to represent itself on the big todo list
  • Statuses
    • #next
      Last step before Complete
    • #waiting
      Waiting for an external event or person
    • #reminder
      In some external system like Reminders
  • Priorities get set by number of asterisks, consecutively, so highest is *****
  • Notes
    • Searches
      All the searches (vary the number of asterisks by deleting with backspace)
      • #task #next *****
      • #task #reminder *****
        Tasks in a reminder system elsewhere
      • #task #waiting *****
      • #task -#waiting -#next -#reminder ******
        Non-queued tasks for moving to Next or Later
      • #project *****
    • This way stuff goes from next to completed

Associated Objects in Swift

Associated Objects are a great way to put properties on classes that you do not control.

For NSObject Subclasses

You must use this method for String and Array, because they are not classes: they're structs. The toll-free bridging to NSObject subclasses allows this to work.

For Custom Objects

Here it's a lot simpler, but since AnyObject is a protocol, you have to use an actual class. This definitely limits the utility of associated objects. My much longer, rambling post on Objective-C and Associated Objects.

Thursday, September 11, 2014

Evernote Links, Old Style

Well, Evernote changed the way they do links. The problem with the https:// links, instead of the older evernote:/// links, is that they require an active Internet connection. And then you have to be logged into your account, etc. And then... they don't work on iOS.

I need this all to be great for Workflowy, so here's a rough Ruby script to handle the issue for OSX.

evernote-links, Ruby Script: Set to Executable!

evernote-links, Applescript for Spark

Use it with Spark to map this to a keystroke. Use an Applescript to launch the Ruby script like this (pointing to wherever you put evernote-links):

Saturday, July 26, 2014

Finally Used My NSNumber Category

I have a category waiting for some classes, and for some reason I had one called NSNumber+Util which had no methods in it. Here's my first! Format a number as 0.000, following international rules!

Tuesday, July 22, 2014

Localizing Nibs Without Creating More Nibs

I have nibs, not Storyboards, and they don't localize well. There is no way that I'm going to maintain multiple NIBs just because I have multiple languages.

Here's a solution I cooked up. Don't localize the nibs at all. Instead, just add a localizationKey property to each element in the NIB that you need to localize, like this:


Then you need the backing categories.