-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlacesModel.m
More file actions
54 lines (42 loc) · 1.18 KB
/
Copy pathPlacesModel.m
File metadata and controls
54 lines (42 loc) · 1.18 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
//
// PlacesModel.m
// Lab6
//
// Created by Lauren Champeau on 4/8/17.
// Copyright © 2017 Lauren Champeau. All rights reserved.
//
#import "PlacesModel.h"
@interface PlacesModel()
// Private properties
@property (nonatomic, strong) NSArray *places;
@end
@implementation PlacesModel
// Shared Model singleton implementation
+ (instancetype) sharedModel{
static PlacesModel *placesModel = nil;
// GCD - Grand Central Dispatch
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
placesModel = [[PlacesModel alloc] init];
});
return placesModel;
}
// init method to read places information from plist
- (instancetype) init{
self = [super init];
if (self){
// Load data from places.plist into an NSArray object
NSString *path = [[NSBundle mainBundle] pathForResource:@"places" ofType:@"plist"];
self.places = [NSArray arrayWithContentsOfFile:path];
}
return self;
}
// Get number of places in a method
- (NSUInteger)numberOfPlaces{
return self.places.count;
}
// Get a place at a particular index in a method
- (NSDictionary *)placeAtIndex:(NSUInteger) index{
return self.places[index];
}
@end