diff options
Diffstat (limited to 'platform/ios/src/MGLUserLocation.m')
-rw-r--r-- | platform/ios/src/MGLUserLocation.m | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/platform/ios/src/MGLUserLocation.m b/platform/ios/src/MGLUserLocation.m index a568ec8be1..97e3f740fc 100644 --- a/platform/ios/src/MGLUserLocation.m +++ b/platform/ios/src/MGLUserLocation.m @@ -26,6 +26,44 @@ NS_ASSUME_NONNULL_END return self; } ++ (BOOL)supportsSecureCoding { + return YES; +} + +- (instancetype)initWithCoder:(NSCoder *)decoder { + if (self = [super init]) { + _location = [decoder decodeObjectOfClass:[CLLocation class] forKey:@"location"]; + _title = [decoder decodeObjectOfClass:[NSString class] forKey:@"title"]; + _subtitle = [decoder decodeObjectOfClass:[NSString class] forKey:@"subtitle"]; + } + return self; +} + +- (void)encodeWithCoder:(NSCoder *)coder { + [coder encodeObject:_location forKey:@"location"]; + [coder encodeObject:_title forKey:@"title"]; + [coder encodeObject:_subtitle forKey:@"subtitle"]; +} + +- (BOOL)isEqual:(id)other { + if (self == other) return YES; + if (![other isKindOfClass:[MGLUserLocation class]]) return NO; + + MGLUserLocation *otherUserLocation = other; + return ((!self.location && !otherUserLocation.location) || [self.location distanceFromLocation:otherUserLocation.location] == 0) + && ((!self.title && !otherUserLocation.title) || [self.title isEqualToString:otherUserLocation.title]) + && ((!self.subtitle && !otherUserLocation.subtitle) || [self.subtitle isEqualToString:otherUserLocation.subtitle]); +} + +- (NSUInteger)hash { + NSUInteger hash = [super hash]; + hash += [_location hash]; + hash += [_heading hash]; + hash += [_title hash]; + hash += [_subtitle hash]; + return hash; +} + + (BOOL)automaticallyNotifiesObserversForKey:(NSString *)key { return ! [key isEqualToString:@"location"] && ! [key isEqualToString:@"heading"]; |