How to add a System User Account on Linux (CentOS)

On both CentOS and Red Hat Linux systems you can easily create new user accounts with their own home directories. Here’s how you do this from the command line. I’m assuming you’re logged in as root, and the new user we’d like to create is called “testuser”: useradd testuser Let’s give our testuser a password … Read more

How to parse a JSON URL in iOS and Cocoa

Both Cocoa and iOS have built-in methods to parse (and generate) JSON data using NSJSONSerialization. Most commonly you’ll want to call a URL with parameters which will return some data. You take this output and tell Objective-C that it’s JSON, then typecast the return to an array or a dictionary which in turn lets you […]

How to use a Selector

Just a quick reminder before I forget (again) how selectors are called: Some of Apple’s pre-written methods use whats known as a Selector. Here’s an example method that uses a selector: // create a bar button item UIBarButtonItem *linkButton = [[UIBarButtonItem alloc]initWithTitle:@”My Title” style:UIBarButtonItemStyleBordered target:self action:@selector(myMethod)]; Notice how the selector is created on the second […]

How to remove the first n characters from an NSString

There’s a convenient method for that by the name of substringFromIndex. This example removes the first character: NSString *complete = @”12345″; NSString *cutOff = [complete substringFromIndex:1]; NSLog(@”%@”, cutOff); // cutOff is now 2345 substringFromString takes only one parameter which specifies where to start the new string. The first character is 0 based, like in arrays. […]