My Links

iOS + Android Developer | CV | work | github | linked in | stack overflow | twitter | rsaunders100 at gmail dot com

29 Jan 2013

Git log --pretty=oneline

For Git, I use:
  • XCode - Just for committing.  It has an excellent interface to see the code changes and its a full blown IDE, so you can edit in the commit pane.
  • The excellent SourceTree for almost everything else.  Its almost replaced the command line for me.  It does a good job of branch management, Cheery picking, merging, rebasing, reverting, reseting.
  • Terminal - for the occasional command.
One really useful terminal commend is the ability to search for a particular piece commt.

git log --pretty=oneline | grep Some Search Text

This puts the commit messages on one line in a nice format and pipes the output though grep which filters it for 'Some Search Text'.  Awesome!


Subclasses Arn't

The following digram should make my point clear.


Subclasses are generally have all the code/methods/functionary of their base class + some extra stuff.  Therefore the subclass contains the superclass which seems to contradict its name  (In maths a superset contains its subset).

Am I the only one to find this confusing?  Im going to stick to base class / derived class from now on.

13 Apr 2012

App development tools setup

Here are the tools I use.

XCode - Install through the mac app store.  Now requires Lion.
Eclipse - For Android development. It works on a mac, but a little fiddly to setup and very clunky compared to XCode.  Search for a setup guide to get going.
Git - Its better than SVN, pretty much the source control standard.
BitBucket / GitHub - GitHub for open source projects, BitBucket for closed source.  GitHub is better, but only free for open source.
Amazon S3.  Simple cheap hosting.
CyberDuck.  A great FTP client, with a nice drag and drop interface.
Dropbox - Good in genreal, but the public folder is especially useful to create 'test feeds', just right click and select copy public link.
TextMate and/or TextWrangler, - for when TextEdit wont cut it.  Make one your default app to handle text files.
Gimp - or something better if you can afford it.
Charles proxy - A great tool, can even monitor HTTPS
Open office + google docs.  Using both you can just about avoid getting MS office.
Terminal - Ships with XCode, make a shortcut in the dock.
iOS Simulator cropper - saves loads of time!
Chrome. My primary browser.  Superior to Safari in my opinion (simpler, faster, and powerful) 
Firefox.  You may need it occasionally.  There is a great add-on called SQLite Manager for viewing databases.
Skype.  For Instant messaging and fast file transfer.
MacPorts.  For easily installation of miscellaneous programs.


5 Apr 2012

New app

I have just finished a puzzle game I buit in my spare time.



Although it looks quite simple, it took quite a bit of time to design and build all the levels.  Here is how I planned out the final structure.



Pattern-Game - Robert Saunders

27 Mar 2012

Quickly crop screenshots for the App Store.

This is a great tool that has saved me loads of time.  Simply drag an drop screenshots and it will remove the status bar.  It also makes promo screenshots with the iPhone border.  Download it direct here, or goto the website.

22 Mar 2012

Lets clients sign their own iOS apps

In terms of security There are 3 type of iOS clients.

  1. The carefree client.  They just want to get it done.  They are more than willing to give out log-in  details and let you submit on their behalf.  
  2. The more careful client.  They are more carful about log in details.  They might send a you the signing certificates, but not itunes credietials.  They will upload the ipa themselfs.
  3. The corporate client.  They will want to own the entire submission process, they have a secirity policy and wont want to share any certificate or password with a 3rd party.

The problem with client number 3 is that they will have to sign an app that you have built.  This is possible but a little tricky.  I will outline how its you can do it, the hardest part is explaining it to the client.

The first thing to note, when you build an iOS app, the certificate you used to code sign is not final.  You can re-sign the code as many times as you like with a different certificates, on different machines.  This is what the organiser is doing when you select "share".  It also allows you to change the profile you signed it with.

Note the option "Dont resign" - This leaves the original code signing intact. 


You can do this manually without Xcode (you still need a Mac with the certificate and private key in the keychain):


  1. First get the .ipa file.  Export it from Xcode using the organiser (click share, dont re-sign then save it anywhere).
  2. Rename the .ipa file to .zip and unzip it
  3. Open the payload folder, right click on the inner file and select "show package contents"
  4. Replace the file called "embedded.mobileprovision" with your new profile.  You can use organiser to extract your profile or you can download it from the provisioning portal)
  5. To resign the app, execute the following command in the terminal: /usr/bin/codesign -f -s "{SIGNER IDENTITY}" {APPLICATION BUNDLE PATH}
  6. Re-zip (right click, then choose "compress") the payload folder.
  7. Rename it to its the original .ipa extension.


For step 5 you may need to go into keychain to get the name of the certificate to sign with.

Copy the common name
The final command will look like this:

/usr/bin/codesign –f –s “iPhone Distribution: Company Name” “/Path to application bundle/MyApplication.app”

I adapted a script to automate this process, you can download it here on on github.  To use, open with AppleScript Editor, save as .app, then drag .ipa and the .mobileprovision files onto it.  You will be prompted for the name of the certificate to sign with.  Again copy and paste the common name from keychain.







17 Feb 2012

NSDateFormatters are Expensive

This is an expensive line of code:

     NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];

I was tasked to find out why the app was loading slow.  It took almost 5 seconds to parsing a list of 500 items.  It turns out it was creating a new NSDateFormatter for each item.

Simply caching the formatters reduced parsing time to 200 ms.  This could be done in a number of ways, e.g. create a singleton with NSDateformatter properties or pass the formatter as a parameter from the parsing class, etc.  I chose a simple fix by having a static formatter in the object class:

static NSDateFormatter* g_dayDateFormatter = nil;
    
// The is called just before the first instance of the class is instantiated.
+ (void) initialize 
{
    g_dayDateFormatter = [[NSDateFormatter alloc] init];
        
    NSLocale* locale = [[[NSLocale alloc] 
                         initWithLocaleIdentifier:@"en_GB"] autorelease];

    [g_dayDateFormatter setLocale:(locale)];
    [g_dayDateFormatter setDateFormat:@"yyyy-MM-dd"];
}

27 Jan 2012

Using Xcode's Jump bar

One of the new features for XCode 4.0 was the jump bar.



A really cool used for this is when you have a large file, you want to find a method so you tap the right most segment to see a list of all methods.  They are listed under neat headings because of the "pragma" preprocessor macro, e.g.

#pragma mark - UITableViewDataSource methods



But you already knew that form Xcode 3 right?  Perhaps what didn't know, you can simply type a few letters to filter on a method name.


Using the shortcut to open the menu (crtl-6), you can then type the first few letters of a method name, hit enter and get exactly where you need to be without even using the mouse.  This is great for large files and even better when you cant quite remember the name of the method you want.

26 Jan 2012

Finding unused images in your project

I game across a nice program to check a XCode project for unused images.  Its based on a Stack Overflow question.

How to use it:

  1. Download this GIST.
  2. Extract it and move it inside to your XCode Project directory.
  3. Navigate to the folder in the terminal.
  4. Run the shell script (type "sh unusedImages.sh").
  5. The program outputs a list of images that it thinks are not used

You have to be careful because the program will give a false positive if the file names are generated dynamically.  E.g. 

NSString *imageName = [NSString stringWithFormat:@"image_%d.png", 1];


The program will say that "image_1.png" is unused.  So be carful when the file name has a numeric suffix.

UIAlertview + Blocks

Some times you need a simple alert view in an app e.g. to confirm a user's action.


UIAlertView* alert =  [[UIAlertView alloc] initWithTitle:@"My App"
                                                 message:@"Are you sure you want to quit?"
                                                delegate:self
                                       cancelButtonTitle:@"Cancel"
                                       otherButtonTitles:@"Ok", nil];
[alert show];
[alert release];


...

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{
    if (buttonIndex == 1) 
    {
        // Exit....
    }
}


Its a little verbose for something so simple, so I created a project to improve this wich uses blocks.  Here is what the code above looks like now


#import "UIAlertView+Blocks.h"

//....


[UIAlertView displayAlertWithTitle:@"My App"
                           message:@"Are you sure you want to quit?"
                   leftButtonTitle:@"Ok" 
                  leftButtonAction:^
  {
    // Exit ...
  } rightButtonTitle:@"Cancel"rightButtonAction:nil];


You must be targeting 4.0 and up (because it uses blocks) and it only supports one or two buttons (iv nerver needed more than 2 buttons before).