forked from erichoracek/MSCollectionViewCalendarLayout
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMSAppDelegate.m
More file actions
76 lines (60 loc) · 3.2 KB
/
Copy pathMSAppDelegate.m
File metadata and controls
76 lines (60 loc) · 3.2 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//
// MSAppDelegate.m
// Example
//
// Created by Eric Horacek on 2/26/13.
// Copyright (c) 2015 Eric Horacek. All rights reserved.
//
#import "MSAppDelegate.h"
#import "MSCalendarViewController.h"
#import "MSEvent.h"
@interface MSAppDelegate ()
- (void)setupRestKitWithBaseURL:(NSURL *)baseURL;
@end
@implementation MSAppDelegate
- (void)setupRestKitWithBaseURL:(NSURL *)baseURL
{
[AFNetworkActivityIndicatorManager sharedManager].enabled = YES;
RKObjectManager *objectManager = [RKObjectManager managerWithBaseURL:baseURL];
// Initialize managed object store
NSManagedObjectModel *managedObjectModel = [NSManagedObjectModel mergedModelFromBundles:nil];
RKManagedObjectStore *managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:managedObjectModel];
objectManager.managedObjectStore = managedObjectStore;
NSEntityDescription *entity = [[managedObjectStore.managedObjectModel entitiesByName] objectForKey:@"Event"];
RKEntityMapping *eventMapping = [[RKEntityMapping alloc] initWithEntity:entity];
[eventMapping addAttributeMappingsFromArray:@[ @"title" ]];
[eventMapping addAttributeMappingsFromDictionary:@{
@"id" : @"remoteID",
@"date_tbd" : @"dateToBeDecided",
@"time_tbd" : @"timeToBeDecided",
@"datetime_utc" : @"start",
@"venue.name" : @"location"
}];
RKResponseDescriptor *eventIndexResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:eventMapping method:RKRequestMethodGET pathPattern:@"events" keyPath:@"events" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[objectManager addResponseDescriptor:eventIndexResponseDescriptor];
[objectManager addFetchRequestBlock:^NSFetchRequest *(NSURL *URL) {
RKPathMatcher *pathMatcher = [RKPathMatcher pathMatcherWithPattern:@"events"];
NSDictionary *argsDict = nil;
BOOL match = [pathMatcher matchesPath:[URL relativePath] tokenizeQueryStrings:NO parsedArguments:&argsDict];
if (match) {
return [NSFetchRequest fetchRequestWithEntityName:@"Event"];
}
return nil;
}];
[managedObjectStore createPersistentStoreCoordinator];
NSString *storePath = [RKApplicationDataDirectory() stringByAppendingPathComponent:@"Example.sqlite"];
[managedObjectStore addSQLitePersistentStoreAtPath:storePath fromSeedDatabaseAtPath:nil withConfiguration:nil options:nil error:nil];
[managedObjectStore createManagedObjectContexts];
managedObjectStore.managedObjectCache = [[RKInMemoryManagedObjectCache alloc] initWithManagedObjectContext:managedObjectStore.persistentStoreManagedObjectContext];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self setupRestKitWithBaseURL:[NSURL URLWithString:@"http://api.seatgeek.com/2/"]];
MSCalendarViewController *calendarViewController = [[MSCalendarViewController alloc] init];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = calendarViewController;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
@end