iOS Auto Layout Debugging Trick

Posted by on June 17, 2016

Debugging Auto Layout issues in most cases can be easy, but there are some times that this is not the case.

Specially when there is a “complicated” layout and your friend “the unsatisfiable layout error” is making your day a pleasure xD

Mainly because you (and me) don’t understand that log printed in the console.

Because, lets be honest, having a memory address reference plus the Auto Layout Visual Format Language is not something “human readable” (Not if you came from another languages, where the developer experience is better)

So, before you close this page, let me tell you the trick: accesibilityIdentifier and contraint identifier property.

As simple as that, use those properties and your printed log will turn into something almost friendly xD

Let me show you some examples.

Before using the accesibiltyIdentifier property and without constraint identifier:

After applying some accesibilityIdentifier:

Now, lets use the constraint identifier property:

Really nice, right?

Another nice thing we get using these properties, is that we can search in XCode for those identifiers :3

But lets go deeper.

What about the Visual Format Language ?

Having something like :

<NSLayoutConstraint:0x7fc0459d9d60 'id15' V:[cell_box(<=83)]   (Names: cell_box:0x7fc0436676c0 )>

Is something i think that can be improved and this is what i see now:

Don´t know about you, but for me having this:

<NSLayoutConstraint:id15[0x7fdb9b5cd8d0] UIView:cell_box[0x7fdb9b543e60].height <= 83>

Its something better.

Also, just in case, the address reference is there, but is something that can be removed.

I was able to get that format thanks to a category available in Mansonry

Specially the category that allows to override the NSLayoutConstraint description.

Check this:–hits-the-fan

But my interest was only related to override that console output to make it friendly.

So, in case you want to use it without depending on Mansonry, you can get a modified version available at:

And thats all folks.

Speed up iOS tests using an alternative application delegate

Posted by on June 10, 2016

Screen Shot 2016-06-08 at 11.04.57

Why skipping the regular launch sequence when testing using an alternative application delegate can be useful ?

You can find your own answer, in my case: speed! and because i want to be able to test host application APIs (to run tests in iPhone environment and test Xib loading and other things) but without all the usual launch sequence.

But what launch sequence i want to avoid?

-> The normal app delegate (and eventually application:didFinishLaunchingWithOptions)

It depends on your app, but it’s not unusual for it to doing things like:

  • Set up all your default data if missing (with Core Data/NSUserDefaults/NSUbiquitousKeyValueStore/Realm/[write yours here])
  • If there is some stored data reconfigure necessary things, like scheduled local notifications
  • Check network reachability
  • Configure the root view controller (in our case if it's the first time there appears a wizard)
  • Retrieve from a server some configuration
  • ... N tasks

Can be a lot of things to do before we even start testing.

So, if all we want is to run our tests, why not avoid all that things?

Lets skip it and use an alternative application delegate to speed up the testing process.

The trick here is to create a new class for example: “QNTestingAppDelegate” and put it in the testing target, but only in the testing target.

Screen Shot 2016-06-08 at 10.39.27

An then in our “main”, if the class is available, lets use it :

Our “QNTestingAppDelegate” Looks like:



And that’s all folks.

Adopting Fastlane for automating our daily iOS developements tasks

Posted by on May 4, 2016



For those who don’t know:  Fastlane is the Holy Grail (the one that Indiana Jones was really looking for, if only he had been an iOS programmer)

Fastlane helps you automate every aspect of your release to the App Store.

It allows coders to deploy app updates from any computer, set up and submit apps more easily, and automate the use of the standard commands required for app revision and testing.

We can even add components on top of Fastlane itself — the tools support customized, user-built actions to extend their functionality.

But what exactly are the usual steps around iOS development and releases to the App Store ?

Current steps (of course can vary):

  • Pull changes from remote repository
  • Run tests (including UI testing) (if got lucky there is nothing to fix)
  • Increment build number (and version number if required)
  • Check provisioning profiles and certificates for code signing (Freddy Krueger was the creator of all this process for sure!)
  • Build new binary version
  • Generate release notes for every supported localisation
  • Take screenshots for every device and every supported localisation
  • Prepare new version on iTunes Connect (and TestFlight)
  • Upload binary to iTunes Connect
  • Share with testers
  • Upload binary to Crashlytics Beta
  • Share with testers
  • Push changes to remote repository


That is a lot to handle in one day!

Because just taking into account the binary build time plus iTunes related stuff time…. got and get your bag to sleep at the office.

Of course, the duration can be different depending on some miracles (cof cof #iosprocessingtime).

So publishing a new version to iTunes App Store is very awkward and time consuming.

But, no more!

Now with a single command:

I do all these steps:

  • Increment project build number
  • Download up-to date provisioning profiles for code signing
  • Build/Archive the app using the correct scheme (QuitNow or QuitNow Pro)
  • Notify to channels (cli, slack, mac os x notification center)
  • Upload a perfectly signed binary to TestFlight/Crashlytics for Beta testers to try

And i just need to use my time in another task while Fastlane save me 30 minutes.

Screen Shot 2016-04-27 at 14.57.21

The last step: “notification” , puts a message at the console and also at the notification center…. a reminder like:

Screen Shot 2016-04-28 at 10.27.45 Fastlane pilot_free task looks like this:

You can improve the process to fit your needs, including running test, syncing changes from remote repositories and much more.

You can even make it to work only on specific git branches and only if they are not dirty. And you can commit changes at the end, like committing the new build number bump and push it to the remote repository.

Lets see our lane for releasing a new version to iTunes:

Another automation example: Generate APNS Certificates containers for your server (PUSH notifications related)

Btw, this post is approved by Felipe


Authentication Challenge with multiple in-house certificate authorities in iOS with Swift

Posted by on March 28, 2016

In one of my recent projects there was a requirement for a certificate and public key pinning. The API performs its operation from servers with certificates signed by an in-house certificate authority (self-signed too of course).

But there are mulitple CA, and clients servers can have different CA, so a hard-coding approach was not the best. So the idea is to validate the certificate to ensure that is was signed by any of the provided trusted CA.

In this example we are going to implement the protocol NSURLSessionDelegate specifically the function which handles server certificate validation

So lets see the code

public func URLSession(session: NSURLSession, didReceiveChallenge challenge: NSURLAuthenticationChallenge, completionHandler: (NSURLSessionAuthChallengeDisposition, NSURLCredential?) -> Void) {
        if challenge.protectionSpace.authenticationMethod == NSURLAuthenticationMethodServerTrust {

            let trust = challenge.protectionSpace.serverTrust
            let rootCaCerts = {
                (data) -> CFData? in
                return CFDataCreate(kCFAllocatorDefault, UnsafePointer(data.bytes), data.length)
                }.filter({$0 != nil}).map() { ref -> CFTypeRef in
                    return SecCertificateCreateWithData(kCFAllocatorDefault, ref!)!
            let certArrayRef : CFArrayRef = CFBridgingRetain(rootCaCerts as NSArray) as! CFArrayRef
            SecTrustSetAnchorCertificates(trust!, certArrayRef)
            SecTrustSetAnchorCertificatesOnly(trust!, true) // if "true" then also allows certificates signed with one of the system available root certificates.
            var trustResult: SecTrustResultType = 0
            SecTrustEvaluate(trust!, &trustResult)
            if (Int(trustResult) == kSecTrustResultUnspecified ||
                Int(trustResult) == kSecTrustResultProceed) {
                    //Trust the server certificate cause its signed with one of the allowed in-house CA
                    let credential = NSURLCredential(forTrust: challenge.protectionSpace.serverTrust!)
                    challenge.sender!.useCredential(credential, forAuthenticationChallenge: challenge)
                    completionHandler(NSURLSessionAuthChallengeDisposition.UseCredential, credential)
            } else {
                print("Invalid server certificate.") //this also happens with expired certificates
                completionHandler(NSURLSessionAuthChallengeDisposition.CancelAuthenticationChallenge, nil)

        } else {
            print("Unexpected authentication method");
            completionHandler(NSURLSessionAuthChallengeDisposition.CancelAuthenticationChallenge, nil)


So, trust or die xD

rootCACertificatesData its an NSData array with the CA certificates file content …. DER encoded certificates added to the project.

So insted of a list with files names, lets find all the “DER” files and load them into an array:

	let enumerator = NSFileManager.defaultManager().enumeratorAtPath(NSBundle.mainBundle().bundlePath)
    while let filePath = enumerator?.nextObject() as? String {
    	if NSURL(fileURLWithPath: filePath).pathExtension == "der" {
        	if let data = NSData(contentsOfURL:(NSBundle.mainBundle().bundleURL.URLByAppendingPathComponent(filePath))) {

New Job and a time for a career reinvention

Posted by on August 30, 2015

Hello everyone,

I know this is not usual post but i want to let you know something very exiting (for me):

I got a new job!

With more than 8 years working in the Hospitality Industry and in the same company as a Software Engineer i thought it was the time for a career change.

Time for new projects and new challenges.

I have been involved in numerous large-scale software releases providing me with a good hands-on experience creating and implementing software achitectures, also the ability to troubleshoot and solve problems in a timely and accurate manner.

As a software engineer, and more recently,

I have:

  • Build enterprise backend services/architecture for high load, high traffic, high availability processes for the Hospitality-Tourism industry, to help Individual and Chains of Properties(Hotels,Restaurants,SPAs,etc) to sell their inventory almost in “real time”, including their rates, enhancements,services, packages, promotions and deals through existing channels.

  • Build a distributed client-server architecture for an Auto-Trade, a Trading system on top of the Award Winning Platform Ninja Trader.

  • Build mobile software for the majors platforms: Android, IOs, Window Phone and HTML5 webapps.

I think that i’m well-seasoned about services/architecture for high load, high traffic, high availability processes (that’s my main area of interest).

So, i have a lot of confidence about my skills on this industry(Hospitality),

But after that long time, and with the job change desicion in mind, some “fears” appeared.

You might not call it fear. But let’s face it. That’s what stops us from making the move out of a “miserable” job, or starting over in a new field no matter how right the time is to do just that.

It’s paralyzing

Some of those fears are:

  • Fear of the unknown
  • Fear of failure
  • Fear of not complying with other people’s expectations
  • Fear of making a bad career change choice
  • Fear of economic stability (having a family to maintain puts more preasure ¬¬)

To be honest.

Right now, i’m a full time Java Enterprise Application Developer.

My job, almost all consist in developing backend services, and

I’m switching to a Mobile career.

Yes, i will continue as a Software Engineer, but on the Mobile side mainly, developing apps and mobile services for Android, iOS, Windows Phone and others.

Rigth time

I don’t know about the future, but i think is and they got me in the rigth time.

Yes, i’m switching, i’m giving my career and oportunity.

I’m really excited about this new job i think is a great opportunity.

I am going into a new adventure with the guys at

They convinced me with : “Come with us and you will be happy”.

The guys at Fewlaps are Master Craftsmen in the development of mobile applications.

I am very happy to become a part of the company and i will work for a great development with my complete knowledge and skills.