Mark On Code

Ongoing adventures in technology.

Macbook Pro Wi-Fi Issues on Mountain Lion

| Comments

I purchased a new Retina Macbook Pro as soon as they were available after drooling over them at the Apple World-Wide Developer Conference 2012. I loved the machine but I kept finding myself hitting problems with Wi-Fi connections.

I never seemed to be able to connect to Wi-Fi hotspots as well as my friends or co-workers with slightly older Macbook Pros and, when I was connected, my machine would either keep dropping off the network every few minutes or the speed would drop to an absolute crawl (less than 1Mbps!).

I hunted all over the web trying to find a solution but all I could find were people complaining about the same issue. Finally I found a comment by someone who suggested that deleting their /Library/Preferences/SystemConfiguration folder solved the problem. I was a little nervous so instead of deleting it I renamed it. Sure enough it solved the problem.

Here are the steps:

  1. Quit out of all applications and save any work
  2. Rename your /Library/Preferences/SystemConfiguration folder to /Library/Preferences/SystemConfiguration.backup
  3. Shutdown the machine completely
  4. While off, hold Shift-Control-Option-Power for 8 seconds, then release
  5. If this worked correctly, then nothing should happen (you’ve just cleared the SMC)
  6. Start the MBP back up and log back on

Now when you re-join your Wi-Fi you should see things flying along a lost faster than before.

NOTE: You will lose all your network connection settings, so make sure you back up rather than delete the SystemConfiguration folder

Hiding Headers for Empty Sections in UITableView

| Comments

While working on a recent iOS application I found my UITableView showing section headings for sections that did not have any rows in them, i.e. the row-count is zero for that section. I read a lot of different opinions on how to hide the section headings for sections with a zero row-count but in the end it turned out to be quite simple.

It turned out to be as simple as returning nil from the titleForHeaderInSection method and of course, 0 in numberOfRowsInSection

So implement the UITableViewDataSource protocol as usual:

TableViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  {
      // Return the number of sections.
      return _sections.count;
  }

  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  {
      // Return the number of rows in the section.
      return _rowsInSection[section].count;
  }

  - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
  {
      return _rowsInSection[section].count ? _sections[section] : nil;
  }

  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      // configure your cell
  }

Hope that helps.

Mark

Managing Multiple Versions of Xcode

| Comments

I don’t know about you, but I am addicted to the ‘new and shiny’. That means I am always on the latest and sometimes not-so-greatest version of every application and tool I use. In the case of Xcode, running beta versions used to be a tricky process thanks to the way Xcode used to be packaged. Now however, thanks to the new app bundle distribution mechanism, having side-by-side installations of Xcode is a piece of cake.

As anyone shipping applications to the iOS App Store knows, you may be able to develop on the latest beta (or even Developer Preview) version of Xcode, but in order to submit to the App Store, you need to use a final released version of Xcode. Fortunately there is a command line tool xcode-select that makes switching easy to do, even switching command-line build script paths.

First open Terminal. Then to see which path all the Xcode tools are currently run xcode-select -print-path:

1
2
$ xcode-select -print-path
/Applications/Xcode.app/Contents/Developer

As you can see, all the developer tools are currently set to use the shipping version of Xcode.

To change to the beta installation of Xcode (in this case 4.5DP4) use xcode-select -switch as super user with the path to the other Xcode installation.

1
sudo xcode-select -switch /Applications/Xcode45-DP4.app

If you now run xcode-select -print-path you will see that the path has been changed to the Xcode 4.5 DP4 directory.

1
2
3
$ sudo xcode-select -switch /Applications/Xcode45-DP4.app
$ xcode-select -print-path
/Applications/Xcode45-DP4.app/Contents/Developer

To verify this let’s take a look at the path of one of the commonly used Xcode utilities opendiff. If you try to see where opendiff resides, however, you will get an interesting answer:

1
2
$ which opendiff
/usr/bin/opendiff

You may have expected something a little different there. If you dig a little deeper you see something even stranger:

1
2
$ ls -la /usr/bin/opendiff
lrwxr-xr-x  1 root  wheel  5 Jul 30 23:42 /usr/bin/opendiff@ -> xcrun

The opendiff command is actually linked to and therefore calling xcrun instead. it turns out xcrun is another tool that Xcode uses to manage path issues in quite an elegant way. Try running xcrun -find opendiff and you will get the answer you were probably expecting when you ran which:

1
2
$ xcrun -find opendiff
/Applications/Xcode45-DP4.app/Contents/Developer/usr/bin/opendiff

Adding a -v gives you the full explanation of what is happening here:

1
2
3
4
5
6
7
8
9
$ xcrun -v -find opendiff
xcrun: note: opening log file '/var/folders/xg/_f7d3jt955q3vhxyj5xd4zth0000gn/T/xcrun_db.log' with mode 'a'
xcrun: note: SDKROOT = ''
xcrun: note: TOOLCHAINS = ''
xcrun: note: DEVELOPER_DIR = '/Applications/Xcode45-DP4.app/Contents/Developer'
xcrun: note: xcrun via opendiff (xcrun)
xcrun: note: database key is: opendiff|||/Applications/Xcode45-DP4.app/Contents/Developer|
xcrun: note: lookup resolved in '/var/folders/xg/_f7d3jt955q3vhxyj5xd4zth0000gn/T/xcrun_db' : '/Applications/Xcode45-DP4.app/Contents/Developer/usr/bin/opendiff'
/Applications/Xcode45-DP4.app/Contents/Developer/usr/bin/opendiff

As you can see, the Xcode developers have put a lot of work behind the scenes to make transitioning between builds of Xcode, and associated developer tools, as easy as possible.

I hope this has been a useful and maybe a little interesting look at managing side-by-side installations of Xcode on OS X.

Mark

Getting JIRA to Work in WebStorm

| Comments

Installing and configuring the JIRA plugin for Webstorm is not hard to do and gives great integration into the IDE.
After installing you will end up with an integrated dashboard like this:

JIRA Dashboard

To install go to preferences and go down to plugins:

WebStorm Preferences

Click on Browse repositories Then type JIRA in the search box.

Browse

Then double click on the Atlassian result.
Now OK all the dialogs. In the status bar you should see the plug-in installing. When it has finished you need to restart.

Now you will see an Atlassian button on the tool bar. After a while (on first load it takes time) you will see the list of bugs assigned to you.

jQueryMobile Pages Flash When Running Full Screen on iOS5

| Comments

There seems to be a bug in jQuery Mobile 1.0 (final) that causes a white full screen flash every time the page transitions to a new page.

It doesn’t manifest if I run the page in mobile Safari but if I run the page as a full-screen app (i.e. creating a shortcut to the web app using “Add to Home Screen” from Safari) and setting the meta tag to

1
<meta name=”apple-mobile-web-app-capable” content=”yes” />

which gets rid of all the browser chrome, then the flashing bug occurs.

Seems there is no fix in the queue yet but a work around has been found. Simply comment out the call to pageTitle.Focus() on line 2326:

1
2
3
4
5
6
7
8
9
10
11
12
//direct focus to the page title, or otherwise first focusable element
function reFocus( page ) {
  var pageTitle = page.find( ".ui-title:eq(0)" );

  if( pageTitle.length ) {
  // MSC comment out next line due to flashing bug on iOS 5  
      // pageTitle.focus();
  }
  else{
      page.focus();
  }
}

Thanks to hhytt for finding this.

How to Mount a Windows File Share in Mac OS X Through the Command Line

| Comments

I switched from Windows to a Mac a year and a half ago, but every now and them I want to do something that just seemed so much easier in Windows. In this case, mount a Windows file share so I can access it from the command line (or script it). Turns out it is pretty easy too if you know the special sauce.

$ mkdir /Volumes/sharename
$ mount -t smbfs -o nosuid,nodev //username@servername/sharename /Volumes/sharename