How to remove a Core Data Model Version
Core Data can handle several versions of your Model. It’s easy to add a version (via Editor – Add Model Version) and set it active, but it’s not so easy to remove a version you no longer need. Thankfully there is a way to delete version files which goes a long way to declutter your brain. The secret lies in the fact that the .xcdatamodeld file is actually a Package and can contain more than one file. It’s like the .app extension which isn’t just one file. I never knew this! To explore, select your versioned...
read moreHow to create a View Controller defined in you your Storyboard programmatically
Your View Controllers are created by the Storyboard automatically depending their defined relationships in Interface Builder. Sometimes however we need to create and transition to View Controllers we’ve defined in code. For example, if you want to transition to a view as part of displaying a search result. We can do this by creating a new UIStoryboard object and then asking it to create a View Controller defined in it. For this to work you need to give your View Controller a unique identifier using the Identity Inspector (under...
read moreHow to add a Search Display Controller to a UITableView (in code)
We’ve recently discussed how to deal with a Search Bar and Search Display Controller using Interface Builder. You can however do this in code too. This can be useful if you don’t want to make all the relevant connections in every Storyboard. This example assumes you have a Table View (self.tableView) to which you’d like to add a Search Bar and Search Display Controller at the top. We do this by utilising the Table View’s tableHeaderView property: // create a new Search Bar and add it to the table view UISearchBar...
read moreHow to change your User Name in WordPress
This week has seen a rather large scale attack of a bot network that specifically targets the “admin” user in WordPress installations. This means that if your site as a user called “admin” then your site is under threat of being a potential target. No matter if you’re using “admin” as an active user or not: if it exists, your site is at risk. Period. In this podcast I’ll show you how to change your user name. Sadly this isn’t as easy as just amending “admin” to something else;...
read moreHow to add a User Account on 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 so s/he can login to the system via SSH: passwd testuser This will prompt for a new password (twice), followed by the message that “all authentication tokens have been updated”. Which...
read moreHow 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 access the data. It’s genius! Here’s an example: // create the URL we'd like to query NSURL *myURL = [[NSURL alloc]initWithString:@"http://domain.com/jsonquery"; // we'll receive raw...
read moreHow 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 line. All it wants to know here is the method name really. Imagine you had a method called myMethod in the...
read moreHow 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. The parameter can’t be longer than the original string’s length for obvious...
read moreHow to create a Fetch Request in the Xcode Model Editor
You can create Fetch Requests in the Xcode model editor, including a Predicate. These are somewhat easier to setup. To create one, select your .xcdatamodeld file, then head over to Editor – Add Fetch Request. Give it a catchy name and a filter property, and much of the above code becomes obsolete. Here’s how you can retrieve one of those in code: // create a fetch request from template NSFetchRequest *fetchRequest = [self.managedObjectModel fetchRequestTemplateForName:@"MyFetch"]; NSArray *fetchedObjects =...
read moreIn the Pipeline at WP Hosting
New year, new company – and behind the scenes we’re busier than ever. It doesn’t show on the front page yet though, so we thought it’s a good idea to keep you guys in the loop of what we’re up to. We’re talking [unordered_list style=”tick”] New Support Forum Video Podcasts Ready Made Websites Affiliate Scheme and our Grand US Tour with WordCamp and Parallels Summit [/unordered_list] New Forum First of all, and just to reiterate this, my WP Guru site is still up and running and will remain as it...
read more