SwiftShell 3

28 May 2017

SwiftShell 3 is finally out of beta, with a much improved readme.

So much so it may even be too long now.

Moderator: parsing commandline arguments in Swift

16 Mar 2017

There are a lot of command line argument parsers written in Swift available on Github, so when I needed one for a client project I was surprised I could not find any which fulfilled these requirements:


  • handle --tag=value.
  • treat unrecognised arguments as an error and list them.

Nor could I find any where it would be relatively easy to add these features, since most just loop through the arguments from first to last and have one big function trying to find out what to do with each of them. That becomes messy quickly.


I think it’s much simpler to create multiple small argument parsers, where each one in turn takes in the list of arguments, removes the ones it wants to handle and passes the rest on to the next one. Any arguments left over are then unrecognised and can be handled accordingly. This way the end user does not need to worry about the order of the arguments. The developer however needs to be careful about the order of the parsers.

FileSmith: Type-safe file handling in Swift

22 Feb 2017

Dealing with file paths in Swift is cumbersome. Using only the standard library leaves us with Strings, which we can join together or split by /. It gets the job done but it’s not pretty, and we need a separate type so our methods can accept file paths exclusively and not just any old String. Foundation gives us this in NSURL/URL, which are also used for internet URLs so their method names are very general and long. E.g. url.deletingPathExtension().lastPathComponent to return the file name without the extension.

Combine markdown files and convert to HTML in a Swift script.

15 May 2016

Swift 3

Sam Burnstone recently wrote about how to convert a simple shell script to Swift. Here’s the same shell script rewritten using SwiftShell and FileSmith.

Building the Swift compiler and Foundation on Linux

24 Apr 2016

Before building the Swift compiler it might be a good idea to check https://github.com/apple/swift to verify the build is currently passing. And to free up as much memory as possible first you can shut down the graphical interface with sudo service lightdm stop.

(has been tested on Ubuntu 15.10):

Move files to the trash with a Swift script

12 Apr 2016

Swift 3

I really don’t like using the ‘rm’ shell command – one misplaced character and you can do some serious damage. But when working in the Finder I don’t think twice about deleting files, because I know I can always get them back from the trash. So here is a Swift shell script which does exactly that – it moves files to the trash instead of deleting them permanently.

The syntax is very simple – all parameters refer to file system items which should be moved to the trash:

trash file.txt a_folder
trash *.m *.h

Cross-platform command line arguments syntax

26 Feb 2016

I’m rewriting Moderator (yet another command-line argument parser), and with Swift now being available for both OS X and Linux (Ubuntu) it should support a syntax which enables applications to fit in on both platforms.

POSIX* is I think the closest thing to a standard for this, so it will be the basis, with some modifications (The Python documentation also has some good insights).

* OS X is POSIX compliant and so is Linux (mostly).

Splitting text read piece by piece

03 Feb 2016

Swift version 2.1.

In the previous post we implemented lazy splitting of collections, very useful for say splitting large texts into lines. But in SwiftShell I need the same functionality for text which is acquired piecemeal, like the output of a long-running shell command read sequentially, when needed. Because shell commands which are piped together in the terminal should get to work right away, and not just hang around waiting for the previous command to finish. Like this:

Both scripts start at the same time. The left one uses the functionality implemented below, while the right one reads the entire input into a string first, and therefore has to wait for the ‘linemaker’ command to finish before doing any actual work.

Splitting text and collections lazily in Swift

18 Jan 2016

Swift version 2.1

There are already methods for splitting collections in the Swift Standard Library, but they do all the work immediately and return the results in an array. When dealing with large strings, or streams of text, I find it better to do the work lazily, when needed. The overall performance is not necessarily better, but it is smoother, as you get the first results immediately instead of having to wait a little while and then get everything at once. And memory usage is lower, no need to store everything in an array first.

SwiftShell 2.0 Readme

12 Nov 2015

I finally got around to updating the SwiftShell 2.0 readme with some actual usage instructions:

SwiftShell: An OS X Framework for command line scripting in Swift.

How to use Swift for shell scripting

16 Sep 2015

To be honest I’m not very good at shell scripting. It’s very useful for automation so I would like to be, but I just don’t like the syntax. For instance, this is how you check if a variable is greater than 100:

#!/bin/bash

if [ $var -gt 100 ]
then
    <do some stuff>
fi

And here’s how to check if the file referred to in the first argument is readable and not empty:

if [ -r $1 ] && [ -s $1 ]

Enough said.

So I would much rather use Swift, as the syntax is nice, very nice indeed. But the things that bash shell scripts actually are good at, like running shell commands and accessing the shell environment, are not that straightforward in Swift. Here’s how you can perform the various tasks using only the Swift Standard Library and Foundation:

Redesigning an API - Swift 2.0 style

02 Sep 2015

SwiftShell (an OS X framework for shell scripting in Swift) is currently using the > operator to combine shell commands, streams and functions, and » to print the results:
// SwiftShell 1

run("echo piped to the next command") |> run("wc -w") |>> standardoutput

// print out line number and content of each line in standard input
var i = 1
standardinput.lines() |> map {line in "line \(i++): \(line)\n"} |>> standardoutput

But Swift 2.0 is here, and it’s clear the way forward is protocols, method chaining and error handling. And being more explicit about what is going on. So for SwiftShell 2 I’m planning something like this:

Swift: mixing default values and variadic parameters.

06 Aug 2015

Update:

As of Xcode 7 beta 6, Swift no longer requires variadic parameters to be last in the function definition. Also argument labels are no longer required when combined with parameters with default values. So this all works fine now:

public func run (executable: String, _ args: String ..., stdinput: String = "default")  {}

run("cmd", stdinput: "not default", "arg1", "arg2")
run("cmd", "arg1", "arg2", stdinput: "not default")
run("cmd", "arg1", "arg2")

The rest of this post is deprecated.

New theme and new host

27 Jun 2015

Did not post anything last week, as I have been busy moving the site over to BlueHost and setting up a new theme. All because I wanted Swift code highlighting, and WordPress.com doesn’t support that. This of course took a lot longer than anticipated, but it’s finally done and if I do say so myself the new theme is simpler and easier to read. So all in all it was worth it.

Parser combinator operators in Swift

15 Jun 2015

This is part of a series on FootlessParser, a parser combinator written in Swift.


Parser combinators must be one of the best things to come out of functional programming. They let you define intuitive parsers right in the code, without any need for pre-processors.

Like this:

let parser = function1 <^> parser1 <*> parser2 <|> parser3

where function1 and parser3 return the same type.

parser will pass the input to parser1 followed by parser2, pass their results to function1 and return its result. If that fails it will pass the original input to parser3 and return its result.

FootlessParser: updated documentation and readme

08 Jun 2015

The FootlessParser project is finally becoming usable and now has brand-new documentation generated by jazzy. The readme has also received some attention and is now actually useful:


FootlessParser is a simple and pretty naive implementation of a parser combinator in Swift. It enables infinite lookahead, non-ambiguous parsing with error reporting.

Also check out a series of blog posts about the development and documentation from the source code.

Making a Numeric Type in Swift

29 May 2015

Fabián Cañas demonstrates something similar to mixins in Swift (for operators):

By defining types (and protocols) around capabilities, and writing functions that target those capabilities, we end up with cleaner and remarkably reusable code when compared to implementing functionality targeting a specific type. The bulk of our final implementation has nothing to do with distances, time intervals, apples, oranges, or anything else. It reads more like a set of statements of fact that any future programmer could adopt if they so chose.

Swift: Associated Types

24 May 2015

Russ Bishop has a clarifying post about Swift protocols and generics:

Type parameters force everyone to know the types involved and specify them repeatedly (when you compose with them it can also lead to an explosion in the number of type parameters). They're part of the public interface. The code that uses the concrete thing (class/struct/enum) makes the decision about what types to select. By contrast an associated type is part of the implementation detail. It's hidden, just like a class can hide its internal ivars. The abstract type member is for the concrete thing (class/struct/enum) to provide later. You select the actual type when you adopt the protocol, not when you instantiate the class/struct. It leaves control over which types to select in a different set of hands.

But I do think he is too harsh on the functional programming hipster kids.

Add Result type and operators

06 May 2015

This is part of a series on FootlessParser, a parser combinator written in Swift.


Add Runes and LlamaKit using Carthage

https://github.com/kareman/FootlessParser/commit/6142452334dae45a5aae65e0f54264f1ea3f533d

Footlessparser is using operators for map ( <^> ), flatmap/bind ( »- ) and apply ( <*> ). Luckily the Runes framework has already defined these, and implemented them for optionals and arrays.

Each parse returns a Result, which has either a tuple containing the output and the remaining unparsed part of the input, or an error description if parsing fails. The Result enum is in the Llamakit framework, later replaced by antitypical/Result.

Add Runes+Result.swift

https://github.com/kareman/FootlessParser/commit/c49709d9bb17291fac6b82a0fe136d6d10e1bd9f

To implement the operators mentioned above for parsers it is very helpful to first implement them for what parsers return, i.e. Result. Gordon Fontenot did just that in this pull request to Runes. It was never merged, so it’s included here.

Rename Runes+Result.swift to Result+Operators.swift

https://github.com/kareman/FootlessParser/commit/74230bb5148e827debf610c8f3c8259b8b4a77b9

I renamed the file later to make the name more descriptive and not so foreign for those who have not heard about the Runes framework.

Switch from LlamaKit/LlamaKit to antitypical/Result.

https://github.com/kareman/FootlessParser/commit/f527d9e0e8999479c4627dd4ffdd5871174b7edf

Later on the Llamakit project recommended switching to antitypical/Result. This lead to several changes:

  • the success and failure functions for making a Result moved to the Result type and became static instead of global. Which is good, functions only involved with one type should be defined in that type.
  • Result became a struct, not an enum. Which seems strange as it is either a success or a failure, never both. It was made back into an enum later.
  • the Result framework brought with it the micro frameworks robrix/Box, robrix/Prelude and robrix/Either. Especially Prelude has some basic functional programming functionality that will come in handy.

Set up an open source Xcode framework project

27 Apr 2015

This is part of a series on FootlessParser, a parser combinator written in Swift.


I find these steps helpful when setting up any new open source framework project in Xcode.

Create project

https://github.com/kareman/FootlessParser/commit/414e3961d3bb2a2df8a257804534578bc7a06461

Create a new project in Xcode, and select OS X framework if it is for both iOS and OS X. The iOS framework target can be added later, besides OS X frameworks are more practical for unit testing. No simulators needed.

Do not select to add it to Git right away. Because of this.

And that’s it. I so do love a fresh project.

Create root folders “tests” and “source” and move stuff in place in Xcode

https://github.com/kareman/FootlessParser/commit/9e43f2f3d284c960c011aa2eecb646df4eb75d15

The file structure of Xcode projects looks better, especially on GitHub, if the code for the product itself is in “source” and the test code in “tests”. It’s better than just dumping all Xcode targets in the root folder. Especially for this project, as it will have test targets for both unit tests, speed tests and integration tests.

Share the only scheme.

https://github.com/kareman/FootlessParser/commit/4eac262ad46fdb846b968d2bb8d5936a3c26d941

Schemes are not shared by default in Xcode. It’s best to share this now since you’re bound to be making changes to it in the future, and if it’s not shared no one else will receive those changes. While you will be merrily coding along, assuming what you see everyone else sees too.

Add license.

https://github.com/kareman/FootlessParser/commit/4ee0dda754593e4355e348d43c7dce4869d00ac6

Which licence to release open source code under is of course entirely a matter of preference. Personally I agree most with the Eclipse licence because I would prefer anyone who make any changes to make them public and open source as well. But I also want my open source projects to be available to as many people as possible, and the MIT license is very popular and compatible with most other licences, including GPL. And it is used by all the open source frameworks this project uses. It is also very short, which is always a good thing for legalese text.

Upload to GitHub

After adding some actual code it’s time to share the work with the world. It is easiest to use GitHub for Mac as it both creates the project on GitHub and uploads the code.

Introduction to FootlessParser

22 Apr 2015

This post is part of a series on FootlessParser, a parser combinator written in Swift.


The goal is to define parsers like this:

let parser = function1 <^> parser1 <*> parser2 <|> parser3

where parser will pass the input to parser1 followed by parser2, pass their results to function1 and return its result. If that fails it will pass the original input to parser3 and return its result.

Terms

Parser

a function which takes some input (a sequence of tokens) and returns either the output and the remaining unparsed part of the input, or an error description if it fails.

Token

a single item from the input. Like a character from a string, an element from an array or a string from a sequence of command line arguments.

Parser Input

most often text, but can also be an array or really any collection of anything, provided it conforms to CollectionType.

First version

Initially FootlessParser will be the simplest possible implementation of a parser combinator in Swift. It will:

  • have at least rudimentary error reporting, because it makes writing parsers so much easier.
  • not parse ambiguous grammars. Each parser will return at most one result, not a list of all possible results.
  • not handle left recursion. Like most parser combinators.
  • probably be slow. It’s going to be very interesting to see how slow.

Future improvements

  • Memoization, should help with speed.
  • Left recursion.
  • Ambiguous grammars (maybe).
  • SequenceType as input.

Writing a parser combinator in Swift

13 Apr 2015

This post is part of a series on FootlessParser, a parser combinator written in Swift.


Before Swift my only contact with functional programming was a couple of half-hearted attempts at reading Erlang, all of them resulting in me running away screaming, clutching my aching head. But learning functional concepts in Swift proved far easier, probably because the syntax is closer to what I was used to. So I read Functional Programming in Swift and everything was well and good until one of the last chapters, “Parser Combinators”, and the headache was back. Luckily I managed to stay quiet and in place this time. I downloaded the code for the chapter, turned it into a framework and hacked away until I had implemented a CSV parser, but I still didn’t really understand it.

The parser library from the book has 6 swift files and more than 50 functions (including operators), all but 10 consisting of only one line. Stepping through the code in the debugger lead to a call stack a mile long which never seemed to reach a function that did some actual work and then returned, instead it appeared to be just functions all the way down. I don’t mean this as criticism of the chapter in particular or functional programming in general, it is more a description of my lack of understanding at that point. So to improve on that and understand functional programming and parser combinators better I am implementing one myself; FootlessParser.

The name comes from the scientific name for Swifts, “Apodidae”, from Greek “apous” meaning “without feet”. The word also has alternate meanings, depending on how the parser turns out it will either be apt or self-deprecating, in any case two of my favourite things.

I will write about the development here. There doesn’t seem to be any complete parser combinator frameworks in Swift out there, hopefully this will be useful to others as well.

BTW I really do recommend the book for anyone interested in functional programming and Swift, it is well written (and offers a real challenge in the last chapters).

Adding an XCode project to Git

18 Jan 2015

When creating a new project in Xcode it is best to leave the “Create Git repository” box unchecked because it will immediately add all files to Git, including those that are specific to you and are of no interest to anyone else. Instead you can run this script from the project folder, which will add only the files that should be under version control:

#!/bin/bash -x

# create the ignore file
cat > .gitignore <<_EOF_
# Xcode
#
.DS_Store
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control?
#
# Pods/
_EOF_

git init
git add .
git commit -m 'Initial commit'

How to use a Mac without hands

08 May 2014

Many people are, like me, unable to use a keyboard and mouse/trackpad for longer periods of time. The solution, as always, is to use your head.

Moving the Mouse Pointer

Note

iTracker doesn’t automatically start controlling the mouse pointer when launched, even if you tell it to in the preferences. Nor will it do anything when you click the icon in the menu bar and select “Track” from the menu. It will only start working when you press the global keyboard shortcut for pausing and resuming iTracker (Cmd-Shift-T by default).

iTracker is the only Mac head mouse software I know of that actually works. It uses the web camera on your Mac to locate your face, see which way it is moving, and move the mouse pointer accordingly. Sounds weird, but it quickly becomes second nature. After adjusting speed and sensitivity you should be able to reach all corners of the screen just by turning your head.

TextSmith - an application for writing

24 Mar 2013

In The ultimate word processor, I described my ideal application for writing. Here is a much more thorough description of its key features and basic workflow.

It’s a bit hard to classify, but here goes:

  • Integrated Writing Environment: Like the Integrated Development Environments (IDE) programmers use, it tries to provide writers with all the tools they need, and lets them adapt it to their workflow.
  • Semantic Text Editor: It lets you describe what the text means as opposed to how it looks.
  • Word Processor: This term is normally used for Word, OpenOffice, Pages etc, but these are more page layout applications than literally “word processors”. TextSmith, with its various plug-ins for importing, transforming and exporting text, can literally perform “word processing”.

But the best description is probably just “Writing Application” (as in; an application for writing).

The ultimate word processor

20 Jan 2011

The ultimate writing software should let you:

  • go back to any previous version of any part of the text.

  • keep different versions of the same part of the text, and easily switch between them.

  • focus on content and structure.

  • write any type of text meant for humans.

  • export to any format imaginable.

  • collaborate with other people.

In May 2004, Adam C. Engst wrote about WriteRight: The Writer’s Word Processor where he laid out his idea of the perfect word processor. Over 6 1/2 years later there is still no such thing. Scrivener is a major leap forward but I feel it is still lacking in some areas, so here I have outlined my own ideas for the perfect writing software. Unfortunately all the good names are taken. The mediocre ones too. So I give you:

Even better UI: Scrivener

16 Dec 2010

Continuing from last week’s ideas for Scrivener’s corkboard, here are some suggestions for the rest of the application.

Preview when configuring a compile

When it’s time to get my writings out of Scrivener, there will often be a lot of back and forth to get the output just the way I want it. It would save a lot of time if there was an instant preview when configuring the compile settings.

If I drag a movie into the Research folder the entire file is moved into the project. This makes the project file way too big, so instead I create aliases of movies and import them. This works fine, but I lose the ability to play the movie inside Scrivener. It would be nice to have the option to link to media files instead of importing them. I know you can link to files in “Document References”, but then they are hidden away somewhere in the Inspector and easily forgotten.

Export files by drag & drop

I have collected a lot of PDF files in the Research folder, but if I drag them out of Scrivener and onto the desktop nothing happens. I can export using File – Export – Files…, but dragging is quicker and more intuitive.

Automatic syncing

When I open a project that has been synchronised with a folder and there are changes in that folder, Scrivener very helpfully informs me of this and asks if I want to synchronise the changes back into the project. But if I make changes in Scrivener and then close the project without synchronising with the folder first, which I often do, nothing happens. It would make for a better workflow if the synchronisation occurred automatically when opening and closing the project.

Enforce format

This is just nitpicking really, but there could be an option to enforce one text format for a document. That way I can forget about how the text looks and focus on the content. All this boils down to is make “Paste and Match Style” the default action when pasting and dragging text.

Even better UI: Scrivener – The Corkboard

07 Dec 2010

Scrivener is an excellent application and the closest anything has come to a great word processor (as opposed to a page layout application, which is what most word processors really are). Fiction and non-fiction writers alike love it, and I fully recommend it for writing anything longer than a blog post. But it’s so full of functionality and customisation options that it can be a bit unintuitive at times. So here are a few ideas for improvements.

How to import voice memos into Things

02 Dec 2010

I usually write new ideas into the Things app on my iPhone straight away, but sometimes it’s better to just dictate into the Voice Memo app instead of typing. Here’s how you automatically add those voice memos to the Things inbox:

  1. Add the folder /Users//Music/iTunes/iTunes Music/Voice Memos to [Hazel](http://www.noodlesoft.com/hazel.php).

  2. Enter these settings: Screenshot of settings in Hazel

Here is the script:

tell application "Things"
   set props to {name:"Voice memo"}
   set newToDo to make new to do with properties props
   set notes of newToDo to "[filepath=" & POSIX path of theFile & "]TITLE[/filepath]"

end tell

Now, every time you make a voice memo on the iPhone and connect it to your computer a note titled “voice memo” with a link to the sound file will be added to the inbox in Things.

If you don’t have Hazel you can achieve the same thing by setting up a folder action on the voice memos folder. But you will have to modify the script.

Auto-saving in OS X

26 Oct 2010

As I mentioned a week ago, I have a strong dislike for the “Save” dialogue boxes that pop up every time you close a document. It seems someone at Apple, and by someone I mean you–know–who, agrees with me. The next version of Mac OS X will include auto-saving and applications will automatically resume where they were when they closed.

 Slide onstage at an Apple keynote event where they introduce auto saving in macOS

In other words; just like on the iPhone. This looks very promising, as long as they still let the rest of us organise our own work in whatever way we want. The iPhone way of having each document exist “inside” the application that created it works fine for casual use, but for any project or task that requires the use of more than one application it is very restricting. We need to be able to keep different types of files that belong together in the same place.

I’m not quite sure how this is going to work though. So lets say you open TextEdit for the first time. An empty document appears. You type some text, move and resize the window, and close the application. Without being asked any questions about saving, name or location. Later you open TextEdit again, and it opens exactly the way it was when you closed it, with the window in the same position and the same size, and the same text inside it. This is as it always should have been.

But then you close the document. Then what? Does the application close too now that there are no documents open? And where can you find the document again? Will all applications come with their own built-in libraries?

If you want to move the document while it’s still open I guess you can select “Move to…” from the “File” menu. Which will have plenty of free space now that the “Save” and “Save as…” items are gone.

Seeing as many (most?) casual computer users don’t really understand the concept of files and folders I hope Apple succeeds in bringing some of the simplicity and usability of the iPhone platform over to the Mac, but without sacrificing the flexibility that easy access to the filesystem provides for the rest of us.

Dumbest question ever

17 Oct 2010

Some survey once showed that the dumbest question known to mankind is “Are you sleeping?” I don’t get it. That seems like a perfectly valid question. If you get no answer it means “yes” and if you get any answer at all it means “no”. Couldn’t be simpler.

No the dumbest question ever must surely be this one:

Screenshot of a dialogue box with the question "do you want to save your changes…"

It is also probably the one question computer users are asked most often. I feel this most pointless of all questions can only be properly answered like this (click to enlarge):

Screenshot of a fake UI with ridiculously long button texts.

I recently started using Scrivener, and it is intelligent enough to just assume that you want to keep your changes when you close a document; it automatically saves while you’re working on it. It also assumes that you are intelligent enough to use the “undo” command if you have made changes you don’t want to keep. I wish more applications would have this kind of confidence in its users.

Dragon Dictate 2.0 for the Mac

12 Oct 2010

I have been a bit harsh on MacSpeech in the past, but since then they have been bought by Nuance (makers of the excellent Dragon NaturallySpeaking dictation software for Windows). If there is anyone who can finally release a decent dictation application for the Mac, it’s them. And recently they released the rebranded Dragon Dictate 2.0. Looking forward to finally not having to launch Windows in Parallels Desktop every time I want to dictate something, this of course filled me with much joy and hope. But judging by MacSpeech’s own forums this version has caused a lot of problems for many people, first and foremost because of a bug which crashes the application when you launch it! After making absolutely sure that I can indeed get my money back within the first 30 days if the application is not working properly and am therefore in no way running the risk of giving even more money to MacSpeech for a faulty product, I bought and installed it. The aforementioned bug was easily avoided by leaving the start-up mode to “Idle - Microphone off”.

Here are the results of the first test:

She sells seashells by the seashore.

Impressive. How about this one:

How much would be debuted chuck chuck if a woodchuck could chuck wood How much would with a booby-trapped truck if it would chop the truck would How much would really would truck truck even good truck woodchuck would

The first one was pretty close, the rest not so much, but in all fairness it’s a very tough phrase. And all in all the accuracy is outstanding. Even better than Dragon NaturallySpeaking 10, which is only natural considering it is using the same underlying engine as Dragon NaturallySpeaking 11. The editing commands are at first confusing for someone who is used to Dragon NaturallySpeaking (when I started this post I was actually planning on doing a fair bit of complaining about them), but by now I’m pretty happy about them. There are occasional crashes and bugs, like sometimes leaving out the last character when dictating single words or punctuation (which, in the latter case, leads to a whole lot of nothing). But when Nuance fixes those I think we finally, at long last, have a good dictation solution for the Mac.

Dictating on a Mac with Dragon NaturallySpeaking

04 Mar 2010

As I have mentioned before I’m not a big fan of MacSpeech Dictate. So I use Dragon NaturallySpeaking in Windows XP running under Parallels Desktop 4 when I need to dictate something. It’s working very well, but it is of course very tedious to have to copy and paste everything I dictate from Windows back into my Mac applications. Luckily Tim Harper has made tightvnc-dns, a Windows application that reroutes the generated keystrokes from Dragon NaturallySpeaking back to the Mac side. You can’t use Dragon to edit the text you dictate this way, but for shorter pieces of text it is very practical.

Icons for your iPhone settings

02 Nov 2009

bjango.com has an interesting article about how and why many developers are moving their settings into the app itself. They even have some icons you can use, both for the tab bar and the toolbar.

Finally released my first App

04 Sep 2009

Today I finally released my first iPhone app ‘Repetitions’. It’s going to be very interesting to see how it does. After reading about how other apps have done I’m not very optimistic, especially since the release date of my app was set to 25 August (when it was accepted by Apple) instead of today when it was actually released. Which of course means my app now appears on page 6 of the “Health and Fitness” category in the AppStore. Where no one will find it. But I will be releasing an update soon anyway, which should put it on the first page at least for a couple of days.

Added mySettings to GitHub

26 Jun 2009

I finally added mySettings to GitHub, using the marvel that is hg-git. It allows me to continue using mercurial, and to push and pull from git repositories. The project on GitHub can be found here. The main place for mySettings will still be on BitBucket, I’m just uploading the code to GitHub to see if it will attract more users and contributors.

Customising a table view with mySettings

21 May 2009

I’ve been working on my iPhone app lately (for performing physical exercises like the ones you get from a physiotherapist, but more about that later) so I haven’t written anything for a long time. I thought I’d rectify that by showing how to create highly customised UIs with fairly little coding. I recently added support for delegates to mySettings and that opened up a lot of possibilities, even with only one method in the delegate (for now).

As an example, here’s the configuration screen for my app:

Configuration screen

Another way to create Settings views

04 May 2009

Craig Hockenberry has also created an API for Settings views. But unlike mySettings his API creates the views from code instead of plists. Like this:

- (void)constructTableGroups
{
NSMutableArray *cells = [NSMutableArray array];
IFTextCellController *textCell = [[[IFTextCellController alloc] initWithLabel:@"Text" andPlaceholder:@"Placeholder" atKey:@"sampleText" inModel:model] autorelease];
[cells addObject:textCell];
IFSwitchCellController *switchCell = [[[IFSwitchCellController alloc] initWithLabel:@"Switch" atKey:@”sampleSwitch” inModel:model] autorelease];
[cells addObject:switchCell];
tableGroups = [[NSArray arrayWithObject:cells] retain];
}

Check it out at http://furbo.org/2009/04/30/matt-gallagher-deserves-a-medal/ .

My Dream Gadget: A Really Big iPod Touch

19 Apr 2009

My idea of the perfect device would essentially be an iPod touch with a screen the size of an A4 sheet of paper. It would be brilliant for surfing the web and reading e-books and PDF’s. Anyone who’s tried to do that on an iPhone or an iPod touch would appreciate not having to scroll for every paragraph. And in addition to running iPhone apps it should be able to remote control a Mac. Just imagine sitting in the living room and using Front Row on this thing. Not to mention playing an adventure game. Only problem is with a touch-screen that big it would probably end up costing as much as a desktop computer. So we probably won’t see it for a couple of years.

But eventually it will be made. It’s just too obvious and idea for it not to.

A UIPickerView with labels

29 Mar 2009

I recently needed a picker view with labels (like the one in the timer tab in the Clock app) to select minutes and seconds for a time interval. So I made the following subclass of UIPickerView:


#import

/**
A picker view with labels under the selection indicator.
Similar to the one in the timer tab in the Clock app.
NB: has only been tested with less than four wheels.
*/
@interface LabeledPickerView : UIPickerView {
    NSMutableDictionary *labels;
}

/** Adds the label for the given component. */
- (void) addLabel:(NSString *)labeltext forComponent:(NSUInteger)component;

@end

mySettings: A Settings API for the iPhone

20 Mar 2009

NB: Unfortunately I am not able to do any more development on this or any other projects. I am hoping that someone else will take over the project and update it. There is also this similar project.A lot of iPhone apps have their own settings views similar to the ones in the Settings App on the iPhone home screen. But to my surprise I couldn’t find any general API for it. So I made my own and published it here. It uses a plist configuration file like the one used by the Settings App, with some added options (and some removed ones, but they will hopefully be implemented in the near future).

In a nutshell it takes a plist like this:

plist

and turns it into this:

iPhone

Features

  • Text fields, on/off switch button, integers and time intervals (with maximum/minimum values and custom format string for the integers). _ More options are needed, obviously, like dates and select lists. Feel free to help out if there are other options you would like to see implemented._

  • Titles can be indented.

  • By default the settings themselves are stored in the standard user defaults object ([NSUserDefaults standardUserDefaults]), but you can use any object that supports key-value coding. This enables you to use your model classes directly in the settings view.

  • And if you don’t find blue pyjama stripes exciting, you can of course change the table view background.

And that’s it for the time being. A work in progress, obviously. I would also like to see support for custom table cells and dynamically filling a section with the contents of an array or a dictionary. And localisation. And sliders. And customising fonts and colours. And lots more cool stuff. So if you want to check it out, follow these instructions. And if you make any changes please let me know so I can merge them back into the repository.

Welcome

20 Mar 2009

Hi, and welcome to my blog. It will almost exclusively be about programming (iPhone-programming to be specific), so if that’s not your particular cup of tea then you’re probably better off with this one. I’m aiming for two or three posts a month, so hopefully I won’t be contributing too much to the unread count of your RSS reader.

PS: I know I’m using the default theme for WordPress, but I really like it and I’ve only seen one other blog using it. If I should happen to come across a better one I might change, but for now I’m happy with this one.