Use NSError correctly

Instead of checking if the error is not nil, one should check the return value of the method invoked.