Question

I've built a command line tool in Objective-C using Xcode 5.0.2. The target OS being OSX and Linux.

At the moment the command line tool takes an argument which is an API key. The API key will be unique for every user that installs the tool. It is obviously very tedious inputting the API key each time the tool is used, so i need to find a solution to this problem.

What I would like to do is allow the user the ability to save the API key against the tool somehow. Something like:

$ mytool config api.key 123456

I've not done this before, so i would like to know what options I have and what are the best practices for doing so.

My gut feeling was to have the tool write to a config file inside the user's home directory called .mytoolconfig and then have the application load this file if it exists, extract the API key and then know not to prompt for it.

Is this approach reasonably sensible or...?

Was it helpful?

Solution

yes. that's how many UNIX CLI save their configs: they write a . file in the home dir ...

if it were ONLY for osx I'd say .. go for ~/Library/Preferences or so but for *nix it is fine to do it like you proposed.

use HSHomeDirectory() and NSFileManager to achieve that


you could (with some modifications) use NSUserDefaults too but for a CLI I wouldn't

  • NOTE: personal preference maybe :D
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top