Skip to content

Instantly share code, notes, and snippets.

View nishabe's full-sized avatar

nish abe nishabe

View GitHub Profile
@nishabe
nishabe / OBJC:Calling Web service using NSURLRequest & Blocks
Last active August 12, 2018 18:19
OBJC:Calling Web service using NSURLRequest & Blocks
- (IBAction)fetchGreeting;
{
NSURL *url = [NSURL URLWithString:@"http://rest-service.guides.spring.io/greeting"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response,
NSData *data, NSError *connectionError)
{
@nishabe
nishabe / OBJC:UIAlertController : 'UIAlertView' is deprecated, use UIAlertController with a preferredStyle
Last active August 12, 2018 18:19
OBJC:UIAlertController : 'UIAlertView' is deprecated, use UIAlertController with a preferredStyle
// UIAlertController example. 'UIAlertView' is deprecated: first deprecated in iOS 9.0 - UIAlertView is deprecated.
// Use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert instead
// More at: http://useyourloaf.com/blog/uialertcontroller-changes-in-ios-8/
- (void) handleError{
UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:nil
message:@"Incorrect Credentials"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction
actionWithTitle:NSLocalizedString(@"OK", @"OK action")
@nishabe
nishabe / OBJC:Calling Web service using NSURLSession & Blocks
Last active August 12, 2018 18:19
OBJC:Calling Web service using NSURLSession & Blocks
// More at http://code.tutsplus.com/tutorials/networking-with-nsurlsession-part-1--mobile-21394
// More samples at: http://hayageek.com/ios-nsurlsession-example/
- (void)viewDidLoad {
[super viewDidLoad];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithURL:[NSURL URLWithString:@"https://itunes.apple.com/search?term=apple&media=software"] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSLog(@"%@", json);
}];
@nishabe
nishabe / OBJC:Update UI from blocks.txt
Last active August 12, 2018 18:20
OBJC:Update UI from blocks
dispatch_async(dispatch_get_main_queue(), ^{
// This block will be executed asynchronously on the main thread.
});
@nishabe
nishabe / OBJC:UIAlertView example.txt
Last active August 12, 2018 18:20
OBJC:UIAlertView example
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"DefaultStyle"
message:@"the default alert view style"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK", nil];
[alertView show];
@nishabe
nishabe / OBJC:GetLocalPathOfSpecificTypeFile.txt
Last active August 12, 2018 18:20
OBJC:Get local path of a specific type file
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"localHtmlSample" ofType:@"html"];
@nishabe
nishabe / OBJC:Get applicationDocumentsDirectory
Last active August 12, 2018 18:20
OBJC:Get applicationDocumentsDirectory
- (NSURL *)applicationDocumentsDirectory {
return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
}
@nishabe
nishabe / OBJC:Get reference of Appdelegate.txt
Last active August 12, 2018 18:21
OBJC:Get reference of Appdelegate.txt
var appDelegate = UIApplication.sharedApplication().delegate as AppDelegate
@nishabe
nishabe / OBJC: Force Only Once Code Execution.txt
Last active August 12, 2018 18:21
OBJC: Force code execution only once
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// Your code here
});
@nishabe
nishabe / OBJC: Suppress a specific compiler warning.txt
Last active August 12, 2018 18:21
OBJC: Suppress a specific compiler warning
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
// Your code here
#pragma clang diagnostic pop