-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoader.m
More file actions
47 lines (33 loc) · 1.43 KB
/
Loader.m
File metadata and controls
47 lines (33 loc) · 1.43 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
//
// Loader.m
// TP2
//
// Created by Valentin Bancarel on 28/05/2015.
// Copyright (c) 2015 bancarelvalentin. All rights reserved.
//
#import "Loader.h"
#import "Vehicule.h"
@interface Loader ()
@end
@implementation Loader
-(void)downloadFile:(NSURL*)url for:(id)delegate{
NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfig delegate:delegate delegateQueue:nil];
NSURLSessionDownloadTask *downloadTask = [session downloadTaskWithURL:url];
[downloadTask resume];
}
-(void)instanciateVehiclesFromJSON:(NSURL *)url andGiveThemTo:(id)delegate{
NSDate *startingDate = [NSDate date];
NSData *JSONData = [NSData dataWithContentsOfFile:[url absoluteString]];
NSError *serializationError;
NSMutableArray* vehiclesJSON = [NSJSONSerialization JSONObjectWithData:JSONData options:0 error:&serializationError];
NSMutableArray* vehicles = [[NSMutableArray alloc] init];
for (NSMutableDictionary* voiture in vehiclesJSON) {
Vehicule* tmp = [[Vehicule alloc] initFromDictionnary:voiture];
[vehicles addObject:tmp];
}
NSNumber *instancingIntervale = [NSNumber numberWithFloat:[[NSDate date] timeIntervalSinceDate:startingDate]];
[delegate showInstancingTime:instancingIntervale];
[delegate receiveVehicles:vehicles];
}
@end