Categories
Blog Uncategorized

First weeks at Automattic

Everyone that is recruited for Automattic (and I mean everyone), spends is first three weeks doing Happiness Rotation an alternative name for Support.

You could think this looks a waste of precious time for some of the people, but actually it’s a brilliant way to understand the business of the company, its clients and all the systems the company has.

Categories
Portfolio

Star Wars Scene Maker

Role: Lead Developer and Game Designer
Client: Disney
Links: Star Wars Scene Maker for iPad

Become the master of your own Star Wars video universe! Create your own scenes, choose your favorite characters, control their actions and dialogue, record your masterpiece, and share your Star Wars story! The Force of your imagination is with you!

Update: Star Wars Scene Maker receive a Tillywid award 

 

Categories
Portfolio

Charles Stanley Mobile App

cs

Role: Lead Architect for the mobile projects  and Lead Developer for the iOS app.
Client: Charles Stanley
Links: Apple App Store

The Charles Stanley Direct mobile APP is the company’s first foray into smart applications and delivers news, features and research from the country’s leading direct-to-consumer investment platform. Charles Stanley Direct is an award-winning and innovative digital service backed by one of the country’s longest established investment management companies (Charles Stanley Group PLC) who can trace its origins back to 1792 and whose name first appeared on the London Stock Exchange in 1852. Always a leader and innovator, Charles Stanley Direct is the digital and mobile-ready arm of this £20 billion business and continually tops comparison tables in the UK against the leading D2C platforms. Recently the company was voted as “leading Innovation in Consumer Platforms” at the Aberdeen UK Platform Awards 2015 and was also named by Boring Money as the “best for ISA accounts at £10,000”. Charles Stanley Direct continues to deliver outstanding personal service to its digital D2C clients and challenges the longer established players with continual upgrades, pricing models and products.

Categories
Blog

Create an IPA using xCodeBuild

Xcode 5 brought a lot of improvements to the xCodeBuild command line tool. The most acclaimed by the developer community was that you finally can run your unit tests trough the command line using the Test build action.

Beside the Test action there was another big improvement: the new -exportArchive option. This new option allows to export archive to IPAs trough the command line and signed them with a designated profile. No more need of the xcrun PackageApplication.

Where before you did something like this:

xcrun -log -sdk iphoneos PackageApplication "$OUTPUTDIR/$APPNAME.app" -o "$OUTPUTDIR/$APPNAME.ipa" -sign "$DEVELOPER_NAME" -embed "$PROVISIONING_PROFILE"

You can now do this:

# First build the archive
xcodebuild archive -scheme $SCHEME_NAME -archivePath $ARCHIVE_NAME
# Then export it to an IPA
xcodebuild -exportArchive -archivePath $ARCHIVE_NAME.xcarchive -exportPath $ARCHIVE_NAME -exportFormat ipa -exportProvisioningProfile "$PROVISIONING_PROFILE" -exportSigningIdentity "$DEVELOPER_NAME"

The syntax is very similar to the PackageApplication command, you just need to create your archive first then export it to the IPA format. For Mac developers out there you can also export to the APP or PKG format.

Categories
Blog

A better UIAppDelegate

One of the most common ugly patterns I see while reviewing iOS code is the overcrowding of the UIAppDelegate with calls for all kinds of services. It all starts with the CoreData stack setup code, then someone adds code to setup an analytics service, short followed by a Push Notification service, InApp Purchase, Crash Reporter, etc…

Before you notice it the AppDelegate gets hundreds of lines of unrelated code, hard to maintain and gets to be a central point of all dependencies. One simple pattern can help us to break this cycle: Delegation.

For each of the services create a controller class that represents that functionality and then delegate the necessary calls from the UIApplicationDelegate to the controller. Let’s see an example with the CoreData code.

Start by creating a Master-Detail Application projet using the XCode and select the CoreData option. You will get an AppDelegate with the following properties and methods:

@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;

@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;

@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;

- (void)saveContext;

Why do we need these methods to be were? We can be easily be moved them to a singleton class called DataController and then refer to it instead implementing them in the AppDelegate. The interface of this object can look like this:

@interface SEDataController : NSObject

@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;

+ (SEDataController *)sharedInstance;
- (void)saveContext;
- (NSURL *)applicationDocumentsDirectory;

But this will only solve part of the issue, we still have calls being made on the AppDelegate to the singleton. Instead of flooding the AppDelegate with calls on each delegate method we can make our controllers implement UIApplicationDelegate protocol.

@interface SVEDataController : NSObject 

@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;

+ (SVEDataController *)sharedInstance;
- (void)saveContext;
- (NSURL *)applicationDocumentsDirectory;</pre>
and then on the .m file we implement the UIApplicationDelegate methods that make sense for this service:
<pre>#pragma mark - UIApplicationDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [self managedObjectContext];
    return YES;
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    [self saveContext];
}

For this methods to work you need to refactor your AppDelegate in a way that it forwards the calls to available services

- (NSArray *) services {
    static NSArray * _services;
    static dispatch_once_t _onceTokenServices;
    dispatch_once(&amp;_onceTokenServices, ^{
        _services = @[[SVEDataController sharedInstance]];
    });
    return _services;
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    id service;
    for(service in self.services){
        if ([service respondsToSelector:@selector(application:didFinishLaunchingWithOptions:)]){
            [service application:application didFinishLaunchingWithOptions:launchOptions];
        }
    }
}

As you can see we know have a service array that holds all of our services. These services can them respond to the UIApplicationDelegate selectors that are relevant for their execution.

You can now easily add more services, for more services  check the example project for SVEApplicationDelegate in github.

Categories
Blog

OCLint

While developing for iOS one of tools that I missed a lot from my C# projects  was FxCop. FxCop was a tool that analysed your assemblies and reports information about the assemblies, such as possible design, localization, performance, and security improvements.  On Xcode the only similar tools is the static analyser but it’s scope its limited to memory issues.

So it was with great excitment  that I found out about the OCLint project. As they say in their website

OCLint is a static code analysis tool for improving quality and reducing defects by inspecting C, C++ and Objective-C code and looking for potential problems

  • Possible bugs – empty if/else/try/catch/finally statements
  • Unused code – unused local variables and parameters
  • Complicated code – high cyclomatic complexity, NPath complexity and high NCSS
  • Redundant code – redundant if statement and useless parentheses
  • Code smells – long method and long parameter list
  • Bad practices – inverted logic and parameter reassignment

The documentation is excellent and it’s very simple to integrate it to Xcode or better yet to your Jenkins build server ( just missing a easy way to use it on Travis CI easily can someone provide a brew for it?).

My selected approach was using it with xctool but I need to tweak a bit the default values :(20 characters for a objective C variable name is a bit on the short side). Here is the script that I’m using at the moment for Xcode

For Jenkins I’m using this variation that allows to create PMD reports

Categories
Blog

Styling your app

One of the great challenges in iOS development is how to do the styling if your app in a easy maintainable way.
A lot of people start by doing it in their nib or storyboards directly, but they quickly find the limitations: no way to set custom fonts in your components, no way to refer any kind of global variables for things like background color or image, standard offsets etc…

My favourite approach at the moment is to set all these values by code on viewDidLoad methods using the help of category methods on UIFont, UIColor, UIImage, UIFont and others.

To help in more tricky styling I sometimes use the Paint Code App (Apple should copy some  of the ideas here to their IB editor)

Recently I found a very powerful alternative: Pixate. This tools is a iOS framework that allows you to style your interface using CSS files. It even allows download and applying of style files while the application is running! I’m seriously considering giving it a go it for my next project.

Categories
Blog

Fast Android Emulators

One of the big pains of Android development was the lack of a fast Android emulator to test apps. Until recently to do any kind of development you need to own a actual device and with the fragmentation on Android this could very expensive…

Say hello to GenyMotion a company that provide super fast emulators. They are based on Virtual Box  images done for Intel processors and they even support Google APIs.

Android programmers heaven!

Categories
Blog

Third Party Continuous Integration for iOS

Until recently if we wanted to have continuous integration for your iOS project we needed to create your own solution, normally it involved the creation of a Jenkins instance in a MacMini. Now with  Xcode 5 and the OSX Server we also have an official Apple alternative in the form of Xcode bots, but you still need fork for your own server.

Luckily in  the last months a lot of third party services are starting to appear that provide a good service, for private repositories and with decent prices.

  • Travis-CI, a big player in the open source projects, providing automatic building for thousands of projects in Github, it now has a commercial solution for private repositories. One of the big advantages is that it’s not limited to iOS you can build almost anything on it.
  • Buildozer.IO, a bit cheaper than Travis but only with support for iOS and Android projects.
  • MacBuildServer, still in the beta phase and only for open source projects.

 

Categories
Blog

CocoaDocs

The fine guys from CocoaPods now provide us CocoaDocs a tool to search and view documentation for most  the libraries that are available in their pods repository.

The best thing is that if you have a library and its configured to to be a cocoapod the documentation is automatically generated for you.

The index page is base on the Readme.md file in the repository and the class documentation is generated from the code comments in you classes.

You just need to follow the AppleDoc syntax.