Daily Archives: June 21, 2012

DMTabBar (Cocoa Controls)

Posted by Cocoa Controls at Cocoa Controls
DMTabBar is a simple segmented control / bar that mimics the XCode 4 Inspector segmented control.

image of this control

HMLabel (Cocoa Controls)

Posted by Cocoa Controls at Cocoa Controls
Finder like color label control. include label control, label select field, label select menu item and label cell.

image of this control

The Productive Apple Developer [Boon Chew] (iDevBlogADay)

Posted by Boon Chew at iDevBlogADay


In this guide, I would like to take the opportunity to introduce some tools and techniques to dramatically improve your productivity as an Mac development. Many of these techniques are something I use on a daily basis and they have helped reduce a lot of repetitive and mundane tasks and make me an ever happier Apple developer. This is called applying the DRY principle from code to OS tasks. For example, if you find yourself renaming multiple files into “duck1.png” and “duck2.png” and so on, something is wrong. We Apple developers should never ever repeat ourselves, since we are too busy playing the next gadget from Cupertino, right? Without further delay, let’s get started shall we?


Terminal is a program included with all versions of Mac OS X. It is located in the Utilities folder within the Applications folder. When launched, it provides a line interface to control the underpinnings of the UNIX based operating system. The default UNIX shell in Mac OS X Panther (10.3) or later is Bash.

For a developer, terminal is arguably one of the most important tools in Mac.

iTerm 2 – Terminal on Steroid

iTerm 2 is my favorite replacement for the default Terminal application. It is highly customizable and has many supports like tabs, colors, profiles and custom key bindings. If you are used to moving from word to word in Xcode, or other editors by using “Option + Left Arrow/Right Arrow”, rejoice! Because you can set up these same behaviors in iTerm 2 with little effort:

  1. Go to Bookmarks > Manage Profiles.
  2. Expand Keyboard Profiles and click Global.
  3. Click the + (Add Mapping) button.
  4. Choose cursor left from the Key drop down menu.
  5. Select the Option Modifier checkbox.
  6. Choose send escape sequence from the Action drop down menu.
  7. Enter b and click OK. You can now use Option-Left Arrow to move left/backward from word to word.
  8. Click the + (Add Mapping) button again.
  9. Choose cursor right from the Key drop down menu.
  10. Select the Option Modifier checkbox.
  11. Choose send escape sequence from the Action drop down menu.
  12. Enter f and click OK. You can now use Option-Right Arrow to move right/forward from word to word.

Brew, Homebrew

Homebrew provides a straightforward and flexible way to install UNIX tools that are not included with OSX.

In short, Homebrew is a Mac version of apt-get, gem, or aptitude. It manages UNIX tools. If you are terminal user, after using Homebrew your life will be forever changed. In fact, I bet you can’t stop using it after you tried. Other similar package management systems in Mac are MacPorts or FINK. I don’t like these as much because they are outdated and unstable.

Installing Homebrew is simple:

/usr/bin/ruby -e "$(/usr/bin/curl -fsSL raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)"

Examples of using brew to install softwares:

$ sudo brew install wget $ sudo brew install git $ sudo brew install curl $ sudo brew install git bash-completion

Things move pretty fast in brewland. If you don’t update your brew after 24 hours, you will get a warning message. Update method is just what you can imagine:

sudo brew update

iTerm 2 with Finder: Go2Shell

What’s your most used Terminal command? I bet it is “cd bala bala”. Your situation goes like this: you open your good friend Finder, go to your project folder, coding, open iTerm 2(I hope you are using it now, :) ), cd ~/balabala/myproject/, and do git. Using “cd” all day long is absolutely the most annoying thing. Go2Shell is much simpler.

Go2Shell opens a terminal window to the current directory in Finder


Customize your .bashrc

I’m in favor of Bash, but if you are using sh or zsh, the concept are same, just customize your own profile. It is located in ~/.bashrc. It is the first to load when you open your iTerm 2 window. Use alias command properly to reduce the heavy loads. Alias just replaces a word by another string. Some examples:

alias ll='ls -alF' alias la='ls -A' alias l='ls -CF' alias sshc='ssh root@www.nanaimostudio.com' alias cdo='cd ~/Documents/Projects/OpenSourceProjects/' alias cdp='cd ~/Documents/Projects/' alias s='subl'

There are lots of tutorials talking about how to customize your bash. I will show a few of my own here because it would take a very long chapter to just introduce each one.

Don’t put duplicate lines in the history.


Append to the history file, don’t overwrite it

shopt -s histappend

For setting history length see HISTSIZE and HISTFILESIZE in bash(1)


Check the window size after each command and, if necessary, update the values of LINES and COLUMNS.

shopt -s checkwinsize

Set variable identifying the chroot you work in (used in the prompt below)

if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then     debian_chroot=$(cat /etc/debian_chroot) fi

Some tricks you might like

I can’t help to talk about this topic. It might be a little off topic, so I will be as simple as possible. These are very good tricks.

  • cd – takes you to the previous directory you were in.
  • !! repeats your last command. Most used in the form of “sudo !!”
  • ESC . insert the last arguments from your last bash command.
  • ls -thor list the most recently modified files in a conveniently readable format.
  • history | awk ‘{print $2}’ | awk ‘BEGIN {FS=”|”}{print $1}’ | sort | uniq -c | sort -nr | head top 10 commands used.
  • pushd and popd almost always come in handy
  • for file in *.wav; do lame “$file” “$(basename “$file” .wav).mp3? ; done; Loop

Finder or Path Finder

The original Finder is not very good. It is elegant indeed, but not that convenient. If you have ever used TotalCommand, you will know how powerful a file manage software can be. Path Finder offers additionally capability and control. It is a commercial software and costs $40. I have tried it few times – Path Finder is a great software and worth the price, but I like the simple Finder window more. It is just a personal preference. If you haven’t used Finder yet, you should give it a try.

If you are sticking with Finder, there are some tricks that can make it better. Please leave a comment if you have any suggestions.

  • Rename: type “enter” in any selected file name
  • Create New Folder: Command + Shift + N (New)
  • Connect to Server: AFP:// for mac, SMB:// for windows, or even FTP:// . Shortcut: Command + K
  • Go to the Folder: Command + Shift + G (GO)
  • Command + 1~4 to switch view
  • Command + N to open a new Finder window
  • Command + I to get the information on a Folder or File.


You need a FTP GUI client. Why? With no reason to not get it, and with obvious reason, you have to have one.
Filezilla I don’t recommend it. It is a cross platform FTP software, clearly not very good on Mac style.
Cyberduck My choice of Free software. Clean and fast, with support for FTP, SFTP, WebDAV, and cloud storage like Google, Amazon Cloud.
Transmit Commercial software for $34. Since I don’t have that much requirement for FTP transmissions. I haven’t get a copy for it.


Automator can automate lots of things in Mac and you don’t need to remember a bunch of command and type them in the folder. There is one time, client send us the assets with ipad2 and ipad3 suffix. We need to rename them all to normal name and HD version with @2x suffix. With Automator, it is just few clicks.

  • First, create a service in Automator. Name whatever you want.
  • Second, drag two items: “Get Folder Contents” and “Replace Text” into the work flow. Set other parameters as the image shown below:
  • Save and use it. Select any file or folder in Finder. Choose Finder -> Service -> Rename__(Script name you typed). A window will popup for renaming.


After a using Mac for a while, it becomes slower and slower. There are something we can do to make it faster. I will explain each one of them so you can know how to speed it up or bring it back if any error shows.

  1. First, run Disk Utility to perform a Repair Disk Permissions. It is harmless and can reduce some rare error. It is recommend to run it once for a while.
  2. Clean, use CCleaner or iBoostUp to clean history, system cache and application caches. You can also use CleanApp to uninstall an app and remove it’s related files. It is a important step to bring your old Mac to new life.
  3. Double check if you are using NTFS driver like Paragon NTFS, turn it off if you are not using it. The reason for it is that if you enable spotlight(you should), it will try to create the index in your NTFS partition, which will make the whole system extremely slow. If you have to use it for writing files to NTFS disk, disable spotlight indexing on NTFS disk.
  4. Disable unused items in Login Items window. There are lots of things you don’t need to start it every time you boot your sweet Mac. They are just slowing it more and more. Disable them, leave your favorites only!.
  5. Validate Fonts, some broken or duplicated fonts can also cause problem of slowing the dear Mac machine. Open Font Book App, select all fonts, and then File -> Validate Fonts. Fix error if any shows on Font Book.
  6. Turn off Speech Recognition, and Internet Sharing if you don’t use them. You can also turn off Universal Access and Bluetooth, but “Universal Access” is used by Accessior which is a great software I will introduce later, and my keyboard and mouse are using Bluetooth. I left these two on.
  7. Clean out your unused widget.
  8. Use Onyx to do maintenance. The official site is www.onyxmac.com. Be careful to click the right download link which is www.titanium.free.fr/download.php Be careful of doing anything on it.
  9. Additionally, you can clean up Launch Service. The files can be found at
~/Library/LaunchAgents /Library/LaunchAgents /Library/LaunchDaemons

After I installed Adobe Master Suite, Autodesk Maya, or TeamViewer, it runs some background services after logged in. Just clean the files in the three folders above to disable them. Be sure to backup these files first. More explanation:

Launch daemons can run without a user logged in. Launch daemons cannot display information using the GUI. launch daemon configuration plist files are stored in the /System/Library/LaunchDaemons folder (for those provided by Apple et al) and /Library/LaunchDaemons (for the rest)

Launch agents run on behalf of a user and therefore need the user to be logged in to run. launch agents can display information through the window server. As with launch daemons, launch agent configuration plist files are stored in the /System/Library/LaunchAgents and /Library/LaunchAgents. User launch agents are installed in the ~/Library/LaunchAgents folder.


So that wraps up a few of the best and most useful tools we use as Apple developers. Hope this will make you a more productive Apple developer! What other tools do you use? Comment below so we can compare. Love the list of tools we have introduced? Well then share the developer love on Twitter or Facebook!

How to Add GPS to Your iOS App – Part 1 (iPhone Programming Tutorials)

Posted by Shawn Grimes at iPhone Programming Tutorials

CoreLocation Graphic

In Part 1 of this series, I will introduce you to the very basics of CoreLocation services and getting the location of the device currently being used.

About CoreLocation

The CoreLocation framework provides your app with the ability to get a device’s current location, provided the user of the device has granted your app access to that information.

Location services are provided in two major ways using this framework:

  1. Standard Location Services– This service provides the most accurate location information using a variety of methods including celluar, wifi, and GPS.

    • Most accurate.
    • Consumes the most power and can take a longer time to acquire.
    • Can only be used when your application is in the foreground.
  2. Significant Change Location Services – This service uses cellular data to determine a general idea of where the device is located.

    • Fastest and uses the least amount of power to determine the location.
    • Can also be used to notify your app when a significant change in the location has occurred even if your app is not in focus.

Project Files:

You can download the project files at this github repository: github.com/shawngrimes/Location-and-Map-Sample

Adding Location Frameworks

The first step to adding location services to your project is to add the CoreLocation framework.

Link Binary With Libraries
  1. Select your target and go to the “Build Phases” tab.
  2. Click the “+” button under “Link Binary With Libraries”
  3. Select the CoreLocation framework and click “Add”
Add Core Location Framework

Location Manager

With location services, you create an instance of CLLocationManager. There is usually one instance of this per app so I feel a good place for this is in the App Delegate and then each view can access the current location from the App Delegate.

To start, open your App Delegate header file:

  1. Add #import <CoreLocation/CoreLocation.h> to the top
  2. Specify that your app delegate complies with the Core Location Delegate protocol by changing your @interface line with @interface CFAAppDelegate : UIResponder <UIApplicationDelegate, CLLocationManagerDelegate>
  3. Specify a CLLocationManager property by adding @property (strong, nonatomic) CLLocationManager *locationManager right before the @end statement.

Your App Delegate header file should now look similar to the following:

#import <UIKit/UIKit.h>   //Add Location Framework #import <CoreLocation/CoreLocation.h>   //Specify this app delegate complies with the location manager delegate @interface CFAAppDelegate : UIResponder &lt;UIApplicationDelegate, CLLocationManagerDelegate&gt;   @property (strong, nonatomic) UIWindow *window;   //Add a location manager property to this app delegate @property (strong, nonatomic) CLLocationManager *locationManager;   @end

Creating The Location Manager Object

Switch over to the App Delegate implementation file (.m), and we are going to create our location manager object. The first thing we should do, since we created it as a property of our app delegate, is synthesize the property so add @synthesize locationManager=_locationManager; under the line that reads @synthesize window = _window;.

#import "CFAAppDelegate.h"   @implementation CFAAppDelegate   @synthesize window = _window; @synthesize locationManager=_locationManager;

Now that our property is synthesized, we can create the object. I usually create it in the method application didFinishLaunchingWithOptions:. A Location Manager object is created similar to any other object but there are three important properties you should set after you have alloc’d/init’d.

  1. .purpose – The purpose property is displayed to the user of your app when they are prompted to allow your app to use their location. It gives you a chance to explain what your app is going to do with their location information.
  2. .desiredAccuracy – The desired accuracy property allows you to tell the device how accurate you would like the location information to be. This should be set based on your application’s needs. Don’t set this property to kCLLocationAccuracyBest if you only need to know what city they are in. NOTE: This is the “desired” accuracy, it is not guaranteed. The device will determine the best available information and provide it to you but you are not, however, guaranteed any level of accuracy.
  3. .distanceFilter – The distance filter property tells the location manager how far a device needs to move (horizontally vs. an altitude change) before triggering a new location event. It is measured in meters. You can set the property to kCLDistanceFilterNone to be notified of all events (this is also the default value).

The completed creation of our location manage looks like this:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];     // Override point for customization after application launch.     self.window.backgroundColor = [UIColor whiteColor];     [self.window makeKeyAndVisible];       if(self.locationManager==nil){         _locationManager=[[CLLocationManager alloc] init];         //I'm using ARC with this project so no need to release           _locationManager.delegate=self;         _locationManager.purpose = @"We will try to tell you where you are if you get lost";         _locationManager.desiredAccuracy=kCLLocationAccuracyBest;         _locationManager.distanceFilter=500;         self.locationManager=_locationManager;     }       return YES; }

If you run this now, you should not notice any change in the way your application runs, you also won’t start receiving location information just yet. That comes next…

Starting Location Services

Now that we have our location manager configured, we want to start getting the location. To start the standard location service, you should first check to make sure that location services are enabled. This is done with a simple call to [CLLocationManager locationServicesEnabled] so after we set up our location manager above and before the return YES;, add the following code:

    if([CLLocationManager locationServicesEnabled]){         [self.locationManager startUpdatingLocation];     }

NOTE: If location services are not enabled and you start updating location services, the user will be prompted to enable location services. This could be annoying to the end user if they have to answer “No” every time your app launches.

If you run your app now, you will notice that the user is prompted to enable location services (and it will include the message from the .prompt property of our location manager object).


Receiving Location Changes

We’ve started location services, but now we need to start receiving updates to location changes. This is all done through the CLLocationManagerDelegate protocol. There are a number of available methods to implement for this delegate but the three most important are probably:

  1. – locationManager:didUpdateToLocation:fromLocation:
  2. – locationManager:didFailWithError:
  3. – locationManager:didChangeAuthorizationStatus:

– locationManager:didUpdateToLocation:fromLocation:

Let’s start with receiving an update in location and how to handle that. In our App Delegate implementation file (.m), add the following method placeholder below the @synthesize … statements and above - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method:

-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{   }

One of the first things I like to do is check the timestamp of the newLocation detected. When you first start updating location services, the location manager will receive the last known location of the device, this could be hours or days old depending on the last time location services were used. In my apps, I like to make sure that I have a recent location. This following code will only use a location that has been found in the last 15.0 seconds:

    NSDate* eventDate = newLocation.timestamp;     NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];     if (abs(howRecent) &lt; 15.0)     {         //Location timestamp is within the last 15.0 seconds, let's use it!     }

The next check that I like to perform is to see how accurate the newLocation is. This can be done by looking at the .horizontalAccuracy property. This property tells you how accurate your location information is. As I stated above, you can request to have very accurate locations but you are not guaranteed it. In the illustration below, the newLocation.coordinate is the location the device thinks it is, but in truth the orange circle of the .horizontalAccuracy says that it could be anywhere in that circle.


Your application’s need will determine how accurate of a location you need. Again, if you just need the city the user is in, you won’t need it to be as accurate as if you were trying to find something within walking distance. In the code below, I have set my accuracy threshold to 35.0 meters. This is pretty broad but I have found that it works well indoors as well as out. Insert the following code right after the comment //Location timestamp is within the last 15.0 seconds, let's use it!

        //Location timestamp is within the last 15.0 seconds, let's use it!         if(newLocation.horizontalAccuracy&lt;35.0){             //Location seems pretty accurate, let's use it!             NSLog(@"latitude %+.6f, longitude %+.6f\n",                   newLocation.coordinate.latitude,                   newLocation.coordinate.longitude);             NSLog(@"Horizontal Accuracy:%f", newLocation.horizontalAccuracy);               //Optional: turn off location services once we've gotten a good location             [manager stopUpdatingLocation];         }

The code above will print the new location to the console and then turn off location services. This is an optional step but if you don’t need location services anymore, it’s a smart thing to turn them off to conserve your user’s battery.

This is what our complete delegate method looks like:

-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{     NSDate* eventDate = newLocation.timestamp;     NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];     if (abs(howRecent) &lt; 15.0)     {         //Location timestamp is within the last 15.0 seconds, let's use it!         if(newLocation.horizontalAccuracy&lt;35.0){             //Location seems pretty accurate, let's use it!             NSLog(@"latitude %+.6f, longitude %+.6f\n",                   newLocation.coordinate.latitude,                   newLocation.coordinate.longitude);             NSLog(@"Horizontal Accuracy:%f", newLocation.horizontalAccuracy);               //Optional: turn off location services once we've gotten a good location             [manager stopUpdatingLocation];         }     } }

Now we can run the project again. If you didn’t authorize the app to use location services before, go ahead and do that now. We haven’t done anything with the location at this point except print it out to the console. If you don’t know how to see the console, make sure Xcode is the active window (NOT the simulator) and press ??C

If you are running the project on the simulator and not a device, you may not see any results in the console window. This is because the simulator does not have location services turned on by default. You can simulate a location by selecting the location services simulation in the console window:

Simulate Location

You can also simulate a location in the Simulator by using the Debug menu.

Simulator Location Services

Once a location has been selected, you may need to restart the app to get the new location to show in the console window:

Location In Console

Because we built the location manager into the App Delegate, you can access the device’s current location anywhere in your code by including the AppDelegate header file (.h) in your view controller’s implementation file (.m):

#import "CFAAppDelegate.h"

Then whenever you need to access the location, you can use the following bit of code:

//Make sure location services are enabled before requesting the location if([CLLocationManager locationServicesEnabled]){       CFAAppDelegate *appDelegate=(CFAAppDelegate *)[UIApplication sharedApplication].delegate;     CLLocation *currentLocation=appDelegate.locationManager.location;       //Do what you want with the location... }

About: Shawn Grimes
Shawn is a mobile app developer for ELC Technologies. He is a co-author of the book, iOS 5 Recipes: A Problem-Solution Approach (Recipes Apress). You can follow him on twitter @shawng. Shawn also works with high school students to teach them app development skills through the APPlied Club Program.

WP Like Button Plugin by Free WordPress Templates