-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFetcher.m
48 lines (34 loc) · 1.31 KB
/
Fetcher.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
// Fetcher.m
// MealKing
//
// Created by Jordan White on 9/14/14.
// Copyright (c) 2014 Option White. All rights reserved.
//
#import "Fetcher.h"
@implementation Fetcher
- (NSArray*)fetchFeedWith:(NSString *)inputURL {
//__weak FeedFetcher *weakSelf = self;
__block NSArray *recipes = nil;
NSURL *URL = [NSURL URLWithString:inputURL];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
[NSURLConnection sendAsynchronousRequest: request queue: [NSOperationQueue mainQueue] completionHandler:
^(NSURLResponse* response, NSData* data, NSError* connectionError){
NSLog(@"data is kinda here");
//the same as calling self, but its a safety to make sure self hasn't been set to nil
//since this is inside of a 'block'
recipes = [self extractData: data];
//label.hidden = YES;
}];
return recipes;
}
#pragma mark - extraction
- (NSArray *) extractData: (NSData*) someData {
NSArray *allCourses = [NSJSONSerialization JSONObjectWithData:someData options:0 error:nil];
NSLog(@"The data is downloaded");
//save the data to the phone locally
//NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
//[prefs setObject:allCourses forKey:@"courses"];
return allCourses;
}
@end