Using GoogleMaps and Alamofire on Swift

One of the requirements on an iOS app I’ve been working on recently is the need to load locations from an external API and plot them onto a Google map. This is rather simple in theory however I was running into an issue where the app would crash when trying to load the Google Map after I added the Alamofire cocoapod to my Podfile and throw the following error.

2015-08-19 16:09:56.303 cew-display-prototypes[16820:1347718] CoreData: warning: Unable to load class named 'GMSCachedTile' for entity 'GMSCachedTile'. Class not found, using default NSManagedObject instead.

2015-08-19 16:09:56.303 cew-display-prototypes[16820:1347716] CoreData: warning: Unable to load class named 'GMSCachedObject' for entity 'GMSCachedObject'. Class not found, using default NSManagedObject instead.

2015-08-19 16:09:56.307 cew-display-prototypes[16820:1347718] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSManagedObject tileCoords]: unrecognized selector sent to instance'

After some debugging I realised that the issue arose when attempting to use both ObjectiveC pods (such as GoogleMapsSDK) and Swift libraries such as Alamofire.

A really simple solution is to add -ObjC to your linkers in XCode which will tell it to compile the ObjectiveC pods.

After adding the linker everything compiles and I’m able to use the two pods in unison.

Fixing Vagrant on OSX 10.11 'El Capitan'

If you’ve updated to the latest release of OSX you might’ve noticed that Vagrant no longer works - even after a fresh install.

This is because el capitan prevents anyone, including root, from writing to /usr/bin which is where Vagrant expects to be able to write it’s executable.

Thankfully, fixing this is relatively straight forward, you just have to symlink the executable into /usr/local/bin. Here’s how.

sudo ln -s /opt/vagrant/bin/vagrant /usr/local/bin/vagrant

Remove files from git cache

Accidentally commit a folder or file to git? Add the file name / path to your .gitignore and run this script to remove all files on your ignore list from the git cache.

git ls-files -ci --exclude-standard -z | xargs -0 git rm --cached