-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRWTItemCell.m
executable file
·57 lines (47 loc) · 1.44 KB
/
RWTItemCell.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
49
50
51
52
53
54
55
56
57
//
// RWTItemCell.m
// ForgetMeNot
//
// Created by Chris Wagner on 1/30/14.
// Copyright (c) 2014 Ray Wenderlich Tutorial Team. All rights reserved.
//
#import "RWTItemCell.h"
#import "RWTItem.h"
@implementation RWTItemCell
- (void)prepareForReuse {
[super prepareForReuse];
self.item = nil;
}
- (void)setItem:(RWTItem *)item {
if (_item) {
[_item removeObserver:self forKeyPath:@"lastSeenBeacon"];
}
_item = item;
[_item addObserver:self forKeyPath:@"lastSeenBeacon" options:NSKeyValueObservingOptionNew context:NULL];
self.textLabel.text = _item.name;
}
- (void)dealloc {
[_item removeObserver:self forKeyPath:@"lastSeenBeacon"];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if ([object isEqual:self.item] && [keyPath isEqualToString:@"lastSeenBeacon"]) {
self.detailTextLabel.text = [NSString stringWithFormat:@"Location: %@", [self nameForProximity:self.item.lastSeenBeacon.proximity]];
}
}
- (NSString *)nameForProximity:(CLProximity)proximity {
switch (proximity) {
case CLProximityUnknown:
return @"Unknown";
break;
case CLProximityImmediate:
return @"Immediate";
break;
case CLProximityNear:
return @"Near";
break;
case CLProximityFar:
return @"Far";
break;
}
}
@end