Skip to content

Instantly share code, notes, and snippets.

@cremaschi
Created November 12, 2013 01:55
Show Gist options
  • Save cremaschi/7424077 to your computer and use it in GitHub Desktop.
Save cremaschi/7424077 to your computer and use it in GitHub Desktop.
A category on the NSError to check if it's a "No Internet Connection" error. For example you can use it on a network request completion to display a proper message.
//
// NSError+NoConnection.h
//
// Created by Maurizio Cremaschi on 01/11/2013.
// Copyright (c) 2013 Myfleek Ltd. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSError (NoConnection)
- (BOOL)isNoInternetConnectionError;
@end
//
// NSError+NoConnection.m
//
// Created by Maurizio Cremaschi on 01/11/2013.
// Copyright (c) 2013 Myfleek Ltd. All rights reserved.
//
#import "NSError+NoConnection.h"
@implementation NSError (NoConnection)
- (BOOL)isNoInternetConnectionError
{
return ([self.domain isEqualToString:NSURLErrorDomain] && (self.code == NSURLErrorNotConnectedToInternet));
}
@end
@emadhegab
Copy link

I Think (||) instead of (&&) will do the work cause mostly not both errors is happening together in the same time :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment