The iOS app Workflow is the greatest thing since whatever the last great thing was, and I am diving in head first.
One of the first problems I've run into is the inability of the If
action to detect the absence of a string.
Why would you want to?
Let's say you have a workflow that's processing a JSON result that has optional fields, and there's something you'd like to do, but only if a certain key is present.
So you add a Get Value for Key
action with an If
following it.
If you play around a bit, you'll find that using Get Value for Key
with a key that isn't present will return…well…Nothing
(or at least the functional equivalent).
But If
wants to check whether its input string contains another string.
You don't have to be a philosophy grad student to realize that nothing doesn't contain anything, and you may have also have noticed that an empty string doesn't, either.
So the problem now is how do we transform Nothing
into something that contains a known value, so we can check for it?
Meet your new best helper, Replace Text
. Just replace the input with the input plus our known value, and we're good to go.
But wait…don't we still need to detect Nothing
? We don't want to tack on our marker text when there actually is input, or we still won't be able to differentiate between being and nothingness.
Not a problem. Just enable the Regular Expression option, then set Find Text to ^$
, which means "match the beginning and the end when there's nothing between them".
Now we can replace our empty/non-existent string, but leave every other sort of string alone.
Now about that "known value" I mentioned earlier.
To really make this detection method dependable, it needs to be unique and very unlikely to be contained in a valid input value.
If there is already a clear string value that would never be present when the value is non-blank, we're done.
For instance, if the value I'm checking for can only be the name of a country, there's any number of values I can be fairly confident will never appear (eg. numbers, punctuation, emoji…).
Just for fun, let's pretend our value could be almost anything, including the workflow itself.
To reword our dependability criteria, we need a value that is unique and doesn't even appear in the workflow itself.
Crazy talk, you say? Ha!
Oh…it was clear I already had something in mind? I retract the "Ha!", then.
The key here is that the value doesn't need to be known by we the workflow creator, it just needs to be known to the workflow.
A GUID fetched from a web service should fit the bill, and setgetgo.com has just the service we need
Now we can proceed with a fair amount of confidence.
Provided we can reach the web service (there's always a catch, isn't there?).
You can find a workflow demonstrating both the GUID and blank detection techniques here.