From 8d4a99fa3c2ea3e4ac0a7e171747e66e1c97a8e9 Mon Sep 17 00:00:00 2001 From: Florian Rath Date: Sat, 30 Jul 2016 15:59:26 +0200 Subject: [PATCH 1/2] MOD patched GPXParser to include name and comment in waypoint declarations MOD changed GPXParser to save desc to description property instead of name --- GPXParser/Models/Waypoint.h | 4 ++++ GPXParser/Parsers/GPXParser.m | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/GPXParser/Models/Waypoint.h b/GPXParser/Models/Waypoint.h index 48118a4..1f97686 100644 --- a/GPXParser/Models/Waypoint.h +++ b/GPXParser/Models/Waypoint.h @@ -11,6 +11,10 @@ #import "Fix.h" @interface Waypoint : Fix + @property (nonatomic, strong) NSString *name; +@property (nonatomic, strong) NSString *desc; +@property (nonatomic, strong) NSString *comment; @property (nonatomic, strong) NSString *type; + @end diff --git a/GPXParser/Parsers/GPXParser.m b/GPXParser/Parsers/GPXParser.m index a993d91..981f9ef 100644 --- a/GPXParser/Parsers/GPXParser.m +++ b/GPXParser/Parsers/GPXParser.m @@ -41,6 +41,16 @@ - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName nam self.currentString = [NSMutableString string]; } + // Waypoint name + if ([elementName isEqualToString:@"name"] && self.waypoint) { + self.currentString = [NSMutableString string]; + } + + // Waypoint comment + if ([elementName isEqualToString:@"cmt"] && self.waypoint) { + self.currentString = [NSMutableString string]; + } + // Route if ([elementName isEqualToString:@"rte"]) { if (!self.route) self.route = [Track new]; @@ -73,10 +83,22 @@ - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName names // Waypoint name if ([elementName isEqualToString:@"desc"] && self.waypoint) { + self.waypoint.desc = self.currentString; + self.currentString = nil; + } + + // Waypoint name + if ([elementName isEqualToString:@"name"] && self.waypoint) { self.waypoint.name = self.currentString; self.currentString = nil; } + // Waypoint comment + if ([elementName isEqualToString:@"cmt"] && self.waypoint) { + self.waypoint.comment = self.currentString; + self.currentString = nil; + } + // End waypoint if([elementName isEqualToString:@"wpt"] && self.waypoint) { [self.gpx.waypoints addObject:self.waypoint]; From 1e6196432597fd816cd23920b4a7d5036c4a0286 Mon Sep 17 00:00:00 2001 From: Florian Rath Date: Wed, 3 Aug 2016 15:46:31 +0200 Subject: [PATCH 2/2] ADD added nscoding to GPX, Fix, Track and Waypoint --- GPXParser/MKPolyline+NSCoding.h | 13 +++++++ GPXParser/MKPolyline+NSCoding.m | 69 +++++++++++++++++++++++++++++++++ GPXParser/Models/Fix.h | 2 +- GPXParser/Models/Fix.m | 20 +++++++++- GPXParser/Models/GPX.h | 2 +- GPXParser/Models/GPX.m | 40 ++++++++++++++++--- GPXParser/Models/Track.h | 2 +- GPXParser/Models/Track.m | 34 +++++++++++++--- GPXParser/Models/Waypoint.h | 2 +- GPXParser/Models/Waypoint.m | 26 ++++++++++++- 10 files changed, 191 insertions(+), 19 deletions(-) create mode 100644 GPXParser/MKPolyline+NSCoding.h create mode 100644 GPXParser/MKPolyline+NSCoding.m diff --git a/GPXParser/MKPolyline+NSCoding.h b/GPXParser/MKPolyline+NSCoding.h new file mode 100644 index 0000000..b19d904 --- /dev/null +++ b/GPXParser/MKPolyline+NSCoding.h @@ -0,0 +1,13 @@ +// +// MKPolyline+NSCoding.h +// Vandy Vans +// +// Created by Seth Friedman on 1/4/14. +// Copyright (c) 2014 VandyApps. All rights reserved. +// + +#import + +@interface MKPolyline (NSCoding) + +@end \ No newline at end of file diff --git a/GPXParser/MKPolyline+NSCoding.m b/GPXParser/MKPolyline+NSCoding.m new file mode 100644 index 0000000..efdba21 --- /dev/null +++ b/GPXParser/MKPolyline+NSCoding.m @@ -0,0 +1,69 @@ +// +// MKPolyline+NSCoding.m +// Vandy Vans +// +// Created by Seth Friedman on 1/4/14. +// Copyright (c) 2014 VandyApps. All rights reserved. +// +// @see: https://github.com/VandyApps/vandyvans-ios/blob/master/Vandy%20Vans/MKPolyline%2BNSCoding.m + +#import "MKPolyline+NSCoding.h" + +static NSString * const kXKey = @"x"; +static NSString * const kYKey = @"y"; +static NSString * const kTitleKey = @"title"; +static NSString * const kSubtitleKey = @"subtitle"; + +@interface MKMultiPoint () + +@property (nonatomic, readwrite) MKMapPoint *points; + +@end + +@implementation MKPolyline (NSCoding) + +- (id)initWithCoder:(NSCoder *)aDecoder { + NSArray *xArray = [aDecoder decodeObjectForKey:kXKey]; + NSArray *yArray = [aDecoder decodeObjectForKey:kYKey]; + + NSUInteger count = [xArray count]; + MKMapPoint pointArray[count]; + + for (NSUInteger i = 0; i < count; ++i) { + pointArray[i] = MKMapPointMake([xArray[i] doubleValue], [yArray[i] doubleValue]); + } + + self = [self.class polylineWithPoints:pointArray + count:count]; + + if (self) { + self.title = [aDecoder decodeObjectForKey:kTitleKey]; + self.subtitle = [aDecoder decodeObjectForKey:kSubtitleKey]; + } + + return self; +} + +- (void)encodeWithCoder:(NSCoder *)aCoder { + NSMutableArray *xArray = [NSMutableArray arrayWithCapacity:self.pointCount]; + NSMutableArray *yArray = [NSMutableArray arrayWithCapacity:self.pointCount]; + + for (NSUInteger i = 0; i < self.pointCount; ++i) { + MKMapPoint point = self.points[i]; + + [xArray addObject:@(point.x)]; + [yArray addObject:@(point.y)]; + } + + [aCoder encodeObject:[xArray copy] + forKey:kXKey]; + [aCoder encodeObject:[yArray copy] + forKey:kYKey]; + + [aCoder encodeObject:self.title + forKey:kTitleKey]; + [aCoder encodeObject:self.subtitle + forKey:kSubtitleKey]; +} + +@end \ No newline at end of file diff --git a/GPXParser/Models/Fix.h b/GPXParser/Models/Fix.h index 855daf5..cad55f3 100644 --- a/GPXParser/Models/Fix.h +++ b/GPXParser/Models/Fix.h @@ -9,7 +9,7 @@ #import #import -@interface Fix : NSObject +@interface Fix : NSObject @property (nonatomic, assign) double latitude; @property (nonatomic, assign) double longitude; diff --git a/GPXParser/Models/Fix.m b/GPXParser/Models/Fix.m index 059a63f..c4f216d 100644 --- a/GPXParser/Models/Fix.m +++ b/GPXParser/Models/Fix.m @@ -9,8 +9,6 @@ #import "Fix.h" @implementation Fix -@synthesize latitude=_latitude; -@synthesize longitude=_longitude; #pragma mark - Coordinate @@ -24,4 +22,22 @@ - (NSString *)description { return [NSString stringWithFormat:@"", _latitude, _longitude]; } +#pragma mark - NSCoding + +- (void)encodeWithCoder:(NSCoder *)coder +{ + [coder encodeDouble:self.latitude forKey:@"latitude"]; + [coder encodeDouble:self.longitude forKey:@"longitude"]; +} + +- (id)initWithCoder:(NSCoder *)decoder +{ + if (self = [super init]) + { + _latitude = [decoder decodeDoubleForKey:@"latitude"]; + _longitude = [decoder decodeDoubleForKey:@"longitude"]; + } + return self; +} + @end diff --git a/GPXParser/Models/GPX.h b/GPXParser/Models/GPX.h index 6b133ef..4bd248a 100644 --- a/GPXParser/Models/GPX.h +++ b/GPXParser/Models/GPX.h @@ -9,7 +9,7 @@ #import #import -@interface GPX : NSObject +@interface GPX : NSObject @property (nonatomic, strong) NSMutableArray *waypoints; @property (nonatomic, strong) NSMutableArray *tracks; @property (nonatomic, strong) NSMutableArray *routes; diff --git a/GPXParser/Models/GPX.m b/GPXParser/Models/GPX.m index 824366a..66f9246 100644 --- a/GPXParser/Models/GPX.m +++ b/GPXParser/Models/GPX.m @@ -9,11 +9,6 @@ #import "GPX.h" @implementation GPX -@synthesize tracks=_tracks; -@synthesize routes=_routes; -@synthesize waypoints=_waypoints; -@synthesize filename=_filename; -@synthesize region=_region; #pragma mark - Initialization @@ -29,7 +24,40 @@ - (id)init { #pragma mark - String - (NSString *)description { - return [NSString stringWithFormat:@"", _tracks.count, _routes.count, _waypoints.count]; + return [NSString stringWithFormat:@"", (unsigned long)_tracks.count, (unsigned long)_routes.count, (unsigned long)_waypoints.count]; +} + +#pragma mark - NSCoding + +- (void)encodeWithCoder:(NSCoder *)coder +{ + [coder encodeObject:self.tracks forKey:@"tracks"]; + [coder encodeObject:self.routes forKey:@"routes"]; + [coder encodeObject:self.waypoints forKey:@"waypoints"]; + [coder encodeObject:self.filename forKey:@"filename"]; + + [coder encodeDouble:self.distance forKey:@"distance"]; + + // region to NSData + NSData *regionData = [NSData dataWithBytes:&_region length:sizeof(self.region)]; + [coder encodeObject:regionData forKey:@"region"]; +} + +- (id)initWithCoder:(NSCoder *)decoder +{ + if (self = [super init]) + { + _tracks = [decoder decodeObjectForKey:@"tracks"]; + _routes = [decoder decodeObjectForKey:@"routes"]; + _waypoints = [decoder decodeObjectForKey:@"waypoints"]; + _filename = [decoder decodeObjectForKey:@"filename"]; + + _distance = [decoder decodeDoubleForKey:@"distance"]; + + NSData *regionData = [decoder decodeObjectForKey:@"region"]; + [regionData getBytes:&_region length:sizeof(self.region)]; + } + return self; } @end diff --git a/GPXParser/Models/Track.h b/GPXParser/Models/Track.h index 987b545..bfe34f5 100644 --- a/GPXParser/Models/Track.h +++ b/GPXParser/Models/Track.h @@ -9,7 +9,7 @@ #import #import -@interface Track : NSObject +@interface Track : NSObject @property (nonatomic, strong) NSMutableArray *fixes; @property (nonatomic, strong) MKPolyline *path; @property (nonatomic, strong) MKPolyline *shadowPath; diff --git a/GPXParser/Models/Track.m b/GPXParser/Models/Track.m index f8bf2ed..35a44d8 100644 --- a/GPXParser/Models/Track.m +++ b/GPXParser/Models/Track.m @@ -7,12 +7,10 @@ // #import "Track.h" +#import "MKPolyline+NSCoding.h" + @implementation Track -@synthesize region=_region; -@synthesize fixes=_fixes; -@synthesize path=_path; -@synthesize shadowPath=_shadowPath; #pragma mark - Initialization @@ -26,7 +24,33 @@ - (id)init { #pragma mark - String - (NSString *)description { - return [NSString stringWithFormat:@"", _fixes.count]; + return [NSString stringWithFormat:@"", (unsigned long)_fixes.count]; +} + +#pragma mark - NSCoding + +- (void)encodeWithCoder:(NSCoder *)coder +{ + [coder encodeObject:self.fixes forKey:@"fixes"]; + [coder encodeObject:self.path forKey:@"path"]; + [coder encodeObject:self.shadowPath forKey:@"shadowPath"]; + + NSData *regionData = [NSData dataWithBytes:&_region length:sizeof(self.region)]; + [coder encodeObject:regionData forKey:@"region"]; +} + +- (id)initWithCoder:(NSCoder *)decoder +{ + if (self = [super init]) + { + _fixes = [decoder decodeObjectForKey:@"fixes"]; + _path = [decoder decodeObjectForKey:@"path"]; + _shadowPath = [decoder decodeObjectForKey:@"shadowPath"]; + + NSData *regionData = [decoder decodeObjectForKey:@"region"]; + [regionData getBytes:&_region length:sizeof(self.region)]; + } + return self; } @end diff --git a/GPXParser/Models/Waypoint.h b/GPXParser/Models/Waypoint.h index 1f97686..31245af 100644 --- a/GPXParser/Models/Waypoint.h +++ b/GPXParser/Models/Waypoint.h @@ -10,7 +10,7 @@ #import "Fix.h" -@interface Waypoint : Fix +@interface Waypoint : Fix @property (nonatomic, strong) NSString *name; @property (nonatomic, strong) NSString *desc; diff --git a/GPXParser/Models/Waypoint.m b/GPXParser/Models/Waypoint.m index 78f4adc..243c728 100644 --- a/GPXParser/Models/Waypoint.m +++ b/GPXParser/Models/Waypoint.m @@ -9,8 +9,6 @@ #import "Waypoint.h" @implementation Waypoint -@synthesize name=_name; -@synthesize type=_type; #pragma mark - String @@ -18,4 +16,28 @@ - (NSString *)description { return [NSString stringWithFormat:@"", _name, self.latitude, self.longitude]; } +#pragma mark - NSCoding + +- (void)encodeWithCoder:(NSCoder *)coder +{ + [super encodeWithCoder:coder]; + + [coder encodeObject:self.name forKey:@"name"]; + [coder encodeObject:self.desc forKey:@"desc"]; + [coder encodeObject:self.comment forKey:@"comment"]; + [coder encodeObject:self.type forKey:@"type"]; +} + +- (id)initWithCoder:(NSCoder *)decoder +{ + if (self = [super initWithCoder:decoder]) + { + _name = [decoder decodeObjectForKey:@"name"]; + _desc = [decoder decodeObjectForKey:@"desc"]; + _comment = [decoder decodeObjectForKey:@"comment"]; + _type = [decoder decodeObjectForKey:@"type"]; + } + return self; +} + @end