Commit 3640ff15 authored by Deployer's avatar Deployer

Replacing JSONModel with Mantle because of naming clashes with Swift Optional on 4.1.

parent 42a77d22
......@@ -8,7 +8,7 @@
Pod::Spec.new do |s|
s.name = 'CedarMaps'
s.version = '3.0.0'
s.version = '3.0.1'
s.summary = 'CedarMaps iOS SDK'
# This description is used to generate tags and improve search results.
......@@ -43,5 +43,5 @@ Pod::Spec.new do |s|
s.public_header_files = 'CedarMaps/Classes/**/*.h'
s.dependency 'Mapbox-iOS-SDK', '~> 4.0'
s.dependency 'JSONModel', '~> 1.7'
s.dependency 'Mantle', '~> 2.1'
end
......@@ -2,7 +2,7 @@
static NSString * _Nonnull const kCedarMapsAccessTokenIsReadeyNotification = @"kCedarMapsAccessTokenIsReadeyNotification";
@interface CSAuthenticationManager : NSObject
@interface CSAuthenticationManager: NSObject
@property (nonatomic, strong, readonly, nullable) NSString *clientID;
@property (nonatomic, strong, readonly, nullable) NSString *clientSecret;
......
......@@ -6,15 +6,13 @@
//
#import <Foundation/Foundation.h>
#import <JSONModel/JSONModel.h>
@import CoreLocation;
@protocol CSBoundingBox;
#import <Mantle/Mantle.h>
#import <CoreLocation/CoreLocation.h>
/**
* The class used for creating a rectangular region bu specifying south west and north east coordinates.
*/
@interface CSBoundingBox: JSONModel
@interface CSBoundingBox: MTLModel <MTLJSONSerializing>
/**
......
......@@ -18,37 +18,32 @@
return self;
}
+ (JSONKeyMapper *)keyMapper {
NSDictionary *map = @{ @"northEast": @"ne",
@"southWest": @"sw"
};
return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:map];
+ (NSDictionary *)JSONKeyPathsByPropertyKey {
return @{
@"northEast": @"ne",
@"southWest": @"sw"
};
}
- (void)setNorthEastWithString:(NSString *)string {
_northEast = [self CLLocationFromNSString:string];
+ (NSValueTransformer *)northEastJSONTransformer {
return [MTLValueTransformer transformerUsingForwardBlock:^CLLocation* (NSString *value, BOOL *success, NSError *__autoreleasing *error) {
return [self CLLocationFromNSString:value];
} reverseBlock:^NSString* (CLLocation *location, BOOL *success, NSError *__autoreleasing *error) {
return [NSString stringWithFormat:@"%f,%f", location.coordinate.latitude, location.coordinate.longitude];
}];
}
- (NSString *)JSONObjectForNorthEast {
return [self JSONObjectFromCLLocation:_northEast];
+ (NSValueTransformer *)southWestJSONTransformer {
return [MTLValueTransformer transformerUsingForwardBlock:^CLLocation* (NSString *value, BOOL *success, NSError *__autoreleasing *error) {
return [self CLLocationFromNSString:value];
} reverseBlock:^NSString* (CLLocation *location, BOOL *success, NSError *__autoreleasing *error) {
return [NSString stringWithFormat:@"%f,%f", location.coordinate.latitude, location.coordinate.longitude];
}];
}
- (void)setSouthWestWithString:(NSString *)string {
_southWest = [self CLLocationFromNSString:string];
}
- (NSString *)JSONObjectForSouthWest {
return [self JSONObjectFromCLLocation:_southWest];
}
- (CLLocation *)CLLocationFromNSString:(NSString *)string {
+ (CLLocation *)CLLocationFromNSString:(NSString *)string {
NSArray *comps = [string componentsSeparatedByString:@","];
return [[CLLocation alloc] initWithLatitude:[comps[0] doubleValue] longitude:[comps[1] doubleValue]];
}
- (NSString *)JSONObjectFromCLLocation:(CLLocation *)location {
return [NSString stringWithFormat:@"%f,%f", location.coordinate.latitude, location.coordinate.longitude];
}
@end
......@@ -5,12 +5,12 @@
// Created by Saeed Taheri on 10/25/17.
//
#import <JSONModel/JSONModel.h>
#import <Mantle/Mantle.h>
#import "CSRoute.h"
@interface CSDirectionResponse : JSONModel
@interface CSDirectionResponse : MTLModel <MTLJSONSerializing>
@property (nonatomic, strong, nonnull) NSString *status;
@property (nonatomic, strong, nullable) NSArray<CSRoute *> <CSRoute, Optional> *routes;
@property (nonatomic, strong, nullable) NSArray<CSRoute *> *routes;
@end
......@@ -9,11 +9,15 @@
@implementation CSDirectionResponse
+ (JSONKeyMapper *)keyMapper {
NSDictionary *map = @{ @"routes": @"result.routes"
};
return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:map];
+ (NSDictionary *)JSONKeyPathsByPropertyKey {
return @{
@"routes": @"result.routes",
@"status": @"status"
};
}
+ (NSValueTransformer *)routesJSONTransformer {
return [MTLJSONAdapter arrayTransformerWithModelClass:[CSRoute class]];
}
@end
......@@ -10,7 +10,7 @@
#define CEDARMAPS_RESPONSE_PARSING_ERROR @"Response Parsing Error"
#define CEDARMAPS_UNKNOWN_ERROR @"Unknown Error"
@interface CSError : NSError
@interface CSError: NSError
+ (nonnull NSError *)errorWithDescription:(nonnull NSString *)errorDescription;
......
......@@ -5,17 +5,31 @@
// Created by Saeed Taheri on 10/24/17.
//
#import <JSONModel/JSONModel.h>
#import <Mantle/Mantle.h>
#import "CSRegion.h"
@protocol CSForwardGeocodePlacemark;
@class CSForwardGeocodeComponent;
#pragma mark Components
/**
* Represents placemark components data for a geographic location in a forward geocode request.
*/
@interface CSForwardGeocodeComponent: MTLModel <MTLJSONSerializing>
@property (nonatomic, strong, nullable) NSString *country;
@property (nonatomic, strong, nullable) NSString *province;
@property (nonatomic, strong, nullable) NSString *city;
@property (nonatomic, strong, nullable) NSArray<NSString *> *districts;
@property (nonatomic, strong, nullable) NSArray<NSString *> *localities;
@end
#pragma mark CSForwardGeocodePlacemark
/**
* Represents placemark data for a geographic location in a forward geocode request. Placemark data can be
* information such as the province, city, and street address.
*/
@interface CSForwardGeocodePlacemark: JSONModel
@interface CSForwardGeocodePlacemark: MTLModel <MTLJSONSerializing>
/**
......@@ -33,7 +47,7 @@
/**
English name of the result.
*/
@property (nonatomic, strong, nullable) NSString<Optional> *nameEn;
@property (nonatomic, strong, nullable) NSString *nameEn;
/**
......@@ -45,7 +59,7 @@
/**
A simple generated address from components field.
*/
@property (nonatomic, strong, nullable) NSString<Optional> *address;
@property (nonatomic, strong, nullable) NSString *address;
/**
......@@ -57,7 +71,7 @@
/**
Geometric region of the result.
*/
@property (nonatomic, strong, nullable) CSRegion<Optional> *region;
@property (nonatomic, strong, nullable) CSRegion *region;
@end
......@@ -73,19 +87,3 @@ typedef NS_OPTIONS(NSUInteger, CSPlacemarkType) {
CSPlacemarkTypeLocality = 1 << 5,
};
NSString* _Nonnull stringValueForPlacemarkType(CSPlacemarkType type);
#pragma mark Components
/**
* Represents placemark components data for a geographic location in a forward geocode request.
*/
@interface CSForwardGeocodeComponent: JSONModel
@property (nonatomic, strong, nullable) NSString<Optional> *country;
@property (nonatomic, strong, nullable) NSString<Optional> *province;
@property (nonatomic, strong, nullable) NSString<Optional> *city;
@property (nonatomic, strong, nullable) NSArray<NSString *> <Optional> *districts;
@property (nonatomic, strong, nullable) NSArray<NSString *> <Optional> *localities;
@end
......@@ -9,19 +9,36 @@
@implementation CSForwardGeocodePlacemark
+ (JSONKeyMapper *)keyMapper {
NSDictionary *map = @{ @"identifier": @"id",
@"nameEn": @"name_en",
@"region": @"location"
};
return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:map];
+ (NSDictionary *)JSONKeyPathsByPropertyKey {
return @{
@"identifier": @"id",
@"name": @"name",
@"nameEn": @"name_en",
@"type": @"type",
@"region": @"location",
@"address": @"address",
@"components": @"components"
};
}
+ (NSValueTransformer *)regionJSONTransformer {
return [MTLJSONAdapter dictionaryTransformerWithModelClass:[CSRegion class]];
}
@end
@implementation CSForwardGeocodeComponent
+ (NSDictionary *)JSONKeyPathsByPropertyKey {
return @{
@"country": @"country",
@"province": @"province",
@"city": @"city",
@"districts": @"districts",
@"localities": @"localities"
};
}
@end
NSString* stringValueForPlacemarkType(CSPlacemarkType type) {
......
......@@ -5,12 +5,12 @@
// Created by Saeed Taheri on 10/24/17.
//
#import <JSONModel/JSONModel.h>
#import <Mantle/Mantle.h>
#import "CSForwardGeocodePlacemark.h"
@interface CSForwardGeocodeResponse : JSONModel
@interface CSForwardGeocodeResponse: MTLModel <MTLJSONSerializing>
@property (nonatomic, strong, nonnull) NSString *status;
@property (nonatomic, strong, nullable) NSArray<CSForwardGeocodePlacemark *> <CSForwardGeocodePlacemark, Optional> *results;
@property (nonatomic, strong, nullable) NSArray<CSForwardGeocodePlacemark *> *results;
@end
......@@ -9,4 +9,15 @@
@implementation CSForwardGeocodeResponse
+ (NSDictionary *)JSONKeyPathsByPropertyKey {
return @{
@"results": @"results",
@"status": @"status"
};
}
+ (NSValueTransformer *)resultsJSONTransformer {
return [MTLJSONAdapter arrayTransformerWithModelClass:[CSForwardGeocodePlacemark class]];
}
@end
@import CoreLocation;
#import <CoreLocation/CoreLocation.h>
#import "CSForwardGeocodePlacemark.h"
#import "CSReverseGeocodePlacemark.h"
#import "CSRoute.h"
......
......@@ -140,7 +140,13 @@ typedef void (^CSNetworkResponseCompletionHandler)(NSData * _Nullable data, NSUR
} else if (data != nil) {
NSError *parsingError;
CSReverseGeocodeResponse *reverseGeocodeResponse = [[CSReverseGeocodeResponse alloc] initWithData:data error:&parsingError];
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&parsingError];
if (parsingError != nil) {
completionHandler(nil, parsingError);
return;
}
CSReverseGeocodeResponse *reverseGeocodeResponse = [MTLJSONAdapter modelOfClass:CSReverseGeocodeResponse.class fromJSONDictionary:dict error:&parsingError];
if (parsingError != nil) {
completionHandler(nil, parsingError);
......@@ -279,7 +285,13 @@ typedef void (^CSNetworkResponseCompletionHandler)(NSData * _Nullable data, NSUR
} else if (data != nil) {
NSError *parsingError;
CSForwardGeocodeResponse *forwardGeocodeResponse = [[CSForwardGeocodeResponse alloc] initWithData:data error:&parsingError];
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&parsingError];
if (parsingError != nil) {
completionHandler(nil, parsingError);
return;
}
CSForwardGeocodeResponse *forwardGeocodeResponse = [MTLJSONAdapter modelOfClass:CSForwardGeocodeResponse.class fromJSONDictionary:dict error:&parsingError];
if (parsingError != nil) {
completionHandler(nil, parsingError);
......@@ -361,7 +373,13 @@ typedef enum {
} else if (data != nil) {
NSError *parsingError;
CSDirectionResponse *directionResponse = [[CSDirectionResponse alloc] initWithData:data error:&parsingError];
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&parsingError];
if (parsingError != nil) {
completionHandler(nil, parsingError);
return;
}
CSDirectionResponse *directionResponse = [MTLJSONAdapter modelOfClass:CSDirectionResponse.class fromJSONDictionary:dict error:&parsingError];
if (parsingError != nil) {
completionHandler(nil, parsingError);
......
......@@ -6,7 +6,7 @@
//
#import <UIKit/UIKit.h>
@import CoreLocation;
#import <CoreLocation/CoreLocation.h>
/**
......
......@@ -6,7 +6,7 @@
//
#import <Foundation/Foundation.h>
@import CoreLocation;
#import <CoreLocation/CoreLocation.h>
/**
......
......@@ -7,7 +7,7 @@
#import <Foundation/Foundation.h>
#import "CSMapSnapshotMarker.h"
@import CoreLocation;
#import <CoreLocation/CoreLocation.h>
/**
......
......@@ -5,16 +5,15 @@
// Created by Saeed Taheri on 10/24/17.
//
#import <JSONModel/JSONModel.h>
#import <Mantle/Mantle.h>
#import <CoreLocation/CoreLocation.h>
#import "CSBoundingBox.h"
@import CoreLocation;
/**
*
* Geometric region of a Forward Geocode result.
*/
@interface CSRegion: JSONModel
@interface CSRegion: MTLModel <MTLJSONSerializing>
/**
......
......@@ -9,40 +9,40 @@
@implementation CSRegion
+ (JSONKeyMapper *)keyMapper {
NSDictionary *map = @{ @"boundingBox": @"bb",
};
return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:map];
}
- (void)setBoundingBoxWithNSDictionary:(NSDictionary *)dic {
NSArray *neComps = [[dic objectForKey:@"ne"] componentsSeparatedByString:@","];
NSArray *swComps = [[dic objectForKey:@"sw"] componentsSeparatedByString:@","];
CLLocationCoordinate2D ne = CLLocationCoordinate2DMake([neComps[0] doubleValue], [neComps[1] doubleValue]);
CLLocationCoordinate2D sw = CLLocationCoordinate2DMake([swComps[0] doubleValue], [swComps[1] doubleValue]);
_boundingBox = [[CSBoundingBox alloc] initWithNorthEastCoordinate:ne southWestCoordinate:sw];
}
- (NSDictionary *)JSONObjectForBoundingBox {
if (_boundingBox == nil) {
return nil;
}
return @{@"ne": [NSString stringWithFormat:@"%f,%f", _boundingBox.northEast.coordinate.latitude, _boundingBox.northEast.coordinate.longitude],
@"sw": [NSString stringWithFormat:@"%f,%f", _boundingBox.southWest.coordinate.latitude, _boundingBox.southWest.coordinate.longitude]
+ (NSDictionary *)JSONKeyPathsByPropertyKey {
return @{
@"boundingBox": @"bb",
@"center": @"center"
};
}
- (void)setCenterWithNSString:(NSString *)string {
NSArray *comps = [string componentsSeparatedByString:@","];
_center = [[CLLocation alloc] initWithLatitude:[comps[0] doubleValue] longitude:[comps[1] doubleValue]];
+ (NSValueTransformer *)boundingBoxJSONTransformer {
return [MTLValueTransformer transformerUsingForwardBlock:^id(NSDictionary* dict, BOOL *success, NSError *__autoreleasing *error) {
NSArray *neComps = [[dict objectForKey:@"ne"] componentsSeparatedByString:@","];
NSArray *swComps = [[dict objectForKey:@"sw"] componentsSeparatedByString:@","];
CLLocationCoordinate2D ne = CLLocationCoordinate2DMake([neComps[0] doubleValue], [neComps[1] doubleValue]);
CLLocationCoordinate2D sw = CLLocationCoordinate2DMake([swComps[0] doubleValue], [swComps[1] doubleValue]);
return [[CSBoundingBox alloc] initWithNorthEastCoordinate:ne southWestCoordinate:sw];
} reverseBlock:^id(CSBoundingBox *bb, BOOL *success, NSError *__autoreleasing *error) {
if (!bb) {
return nil;
}
return @{@"ne": [NSString stringWithFormat:@"%f,%f", bb.northEast.coordinate.latitude, bb.northEast.coordinate.longitude],
@"sw": [NSString stringWithFormat:@"%f,%f", bb.southWest.coordinate.latitude, bb.southWest.coordinate.longitude]
};
}];
}
- (NSString *)JSONObjectForCenter {
if (_center == nil) {
return nil;
}
return [NSString stringWithFormat:@"%f,%f", _center.coordinate.latitude, _center.coordinate.longitude];
+ (NSValueTransformer *)centerJSONTransformer {
return [MTLValueTransformer transformerUsingForwardBlock:^id(NSString* string, BOOL *success, NSError *__autoreleasing *error) {
NSArray *comps = [string componentsSeparatedByString:@","];
return [[CLLocation alloc] initWithLatitude:[comps[0] doubleValue] longitude:[comps[1] doubleValue]];
} reverseBlock:^id(CLLocation *center, BOOL *success, NSError *__autoreleasing *error) {
if (center == nil) {
return nil;
}
return [NSString stringWithFormat:@"%f,%f", center.coordinate.latitude, center.coordinate.longitude];
}];
}
@end
......@@ -5,66 +5,64 @@
// Created by Saeed Taheri on 10/24/17.
//
#import <JSONModel/JSONModel.h>
#import <Mantle/Mantle.h>
@class CSTrafficZone;
@class CSReverseGeocodeComponent;
@protocol CSReverseGeocodeComponent;
/**
* Represents placemark data for a geographic location in a reverse geocode request. Placemark data can be
* information such as the province, city, and street address.
*/
@interface CSReverseGeocodePlacemark: JSONModel
@interface CSReverseGeocodePlacemark: MTLModel <MTLJSONSerializing>
/**
Address for the result.
*/
@property (nonatomic, strong, nullable) NSString<Optional> *address;
@property (nonatomic, strong, nullable) NSString *address;
/**
Locality name for the result.
*/
@property (nonatomic, strong, nullable) NSString<Optional> *locality;
@property (nonatomic, strong, nullable) NSString *locality;
/**
District name for the result.
*/
@property (nonatomic, strong, nullable) NSString<Optional> *district;
@property (nonatomic, strong, nullable) NSString *district;
/**
Place name for the result. If it exists.
*/
@property (nonatomic, strong, nullable) NSString<Optional> *place;
@property (nonatomic, strong, nullable) NSString *place;
/**
City name for the result.
*/
@property (nonatomic, strong, nullable) NSString<Optional> *city;
@property (nonatomic, strong, nullable) NSString *city;
/**
Province name for the result.
*/
@property (nonatomic, strong, nullable) NSString<Optional> *province;
@property (nonatomic, strong, nullable) NSString *province;
/**
Traffic zone information for the result.
*/
@property (nonatomic, strong, nullable) CSTrafficZone<Optional> *trafficZone;
@property (nonatomic, strong, nullable) CSTrafficZone *trafficZone;
/**
Detailed address components for the result.
*/
@property (nonatomic, strong, nullable) NSArray<CSReverseGeocodeComponent *> <CSReverseGeocodeComponent, Optional> *components;
@property (nonatomic, strong, nullable) NSArray<CSReverseGeocodeComponent *> *components;
@end
......@@ -76,13 +74,13 @@ typedef void (^CSReverseGeocodeCompletionHandler)(CSReverseGeocodePlacemark* __n
/**
* Traffic zone information for a Reverse Geocode response
*/
@interface CSTrafficZone: JSONModel
@interface CSTrafficZone: MTLModel <MTLJSONSerializing>
/**
Name of the Traffic Zone.
*/
@property (nonatomic, strong, nullable) NSString<Optional> *name;
@property (nonatomic, strong, nullable) NSString *name;
/**
......@@ -103,19 +101,19 @@ typedef void (^CSReverseGeocodeCompletionHandler)(CSReverseGeocodePlacemark* __n
/**
* Detailed components of a Reverse Geocode response
*/
@interface CSReverseGeocodeComponent: JSONModel
@interface CSReverseGeocodeComponent: MTLModel <MTLJSONSerializing>
/**
Short name of the component for a result
*/
@property (nonatomic, strong, nonnull) NSString<Optional> *shortName;
@property (nonatomic, strong, nonnull) NSString *shortName;
/**
Long name of the component for a result
*/
@property (nonatomic, strong, nonnull) NSString<Optional> *longName;
@property (nonatomic, strong, nonnull) NSString *longName;
/**
......
......@@ -9,11 +9,25 @@
@implementation CSReverseGeocodePlacemark
+ (JSONKeyMapper *)keyMapper {
NSDictionary *map = @{ @"trafficZone": @"traffic_zone"
};
return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:map];
+ (NSDictionary *)JSONKeyPathsByPropertyKey {
return @{
@"components": @"components",
@"address": @"address",
@"locality": @"locality",
@"district": @"district",
@"place": @"place",
@"city": @"city",
@"province": @"province",
@"trafficZone": @"traffic_zone"
};
}
+ (NSValueTransformer *)componentsJSONTransformer {
return [MTLJSONAdapter arrayTransformerWithModelClass:[CSReverseGeocodeComponent class]];
}
+ (NSValueTransformer *)trafficZoneJSONTransformer {
return [MTLJSONAdapter dictionaryTransformerWithModelClass:[CSTrafficZone class]];
}
@end
......@@ -22,12 +36,12 @@
@implementation CSTrafficZone
+ (JSONKeyMapper *)keyMapper {
NSDictionary *map = @{ @"inEvenOdd": @"in_evenodd",
@"inCentral": @"in_central"
};
return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:map];
+ (NSDictionary *)JSONKeyPathsByPropertyKey {
return @{
@"name": @"name",
@"inCentral": @"in_central",
@"inEvenOdd": @"in_evenodd"
};
}
@end
......@@ -36,12 +50,12 @@
@implementation CSReverseGeocodeComponent
+ (JSONKeyMapper *)keyMapper {
NSDictionary *map = @{ @"longName": @"long_name",
@"shortName": @"short_name"
};
return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:map];
+ (NSDictionary *)JSONKeyPathsByPropertyKey {
return @{
@"longName": @"long_name",
@"shortName": @"short_name",
@"type": @"type"
};
}
@end
......@@ -5,12 +5,12 @@
// Created by Saeed Taheri on 10/24/17.
//
#import <JSONModel/JSONModel.h>
#import <Mantle/Mantle.h>
#import "CSReverseGeocodePlacemark.h"
@interface CSReverseGeocodeResponse : JSONModel
@interface CSReverseGeocodeResponse: MTLModel <MTLJSONSerializing>
@property (nonatomic, strong, nonnull) NSString *status;
@property (nonatomic, strong, nullable) CSReverseGeocodePlacemark<Optional> *result;
@property (nonatomic, strong, nullable) CSReverseGeocodePlacemark *result;
@end
......@@ -9,4 +9,15 @@
@implementation CSReverseGeocodeResponse
+ (NSDictionary *)JSONKeyPathsByPropertyKey {
return @{
@"result": @"result",
@"status": @"status"
};
}
+ (NSValueTransformer *)resultsJSONTransformer {
return [MTLJSONAdapter dictionaryTransformerWithModelClass:[CSReverseGeocodePlacemark class]];
}
@end
......@@ -5,16 +5,14 @@
// Created by Saeed Taheri on 10/25/17.
//
#import <JSONModel/JSONModel.h>
#import <Mantle/Mantle.h>
#import "CSBoundingBox.h"
#import "CSRouteInstruction.h"
@protocol CSRoute;
/**
* A CSRoute object shows direction and distance information.
*/
@interface CSRoute: JSONModel
@interface CSRoute: MTLModel <MTLJSONSerializing>
/**
......@@ -38,12 +36,12 @@
/**
The location points which make a route.
*/
@property (nonatomic, strong, nullable) NSArray<CLLocation *> <Optional> *points;
@property (nonatomic, strong, nullable) NSArray<CLLocation *> *points;
/**
* Verbal representation of the route.
*/
@property (nonatomic, strong, nullable) NSArray<CSRouteInstruction *> <Optional, CSRouteInstruction> *instructions;
@property (nonatomic, strong, nullable) NSArray<CSRouteInstruction *> *instructions;
@end
......
......@@ -13,62 +13,68 @@
return _time / 1000;
}
- (void)setBoundingBoxWithNSArray:(NSArray *)array {
if (array && array.count == 4) {
CLLocationCoordinate2D ne = CLLocationCoordinate2DMake([array[3] doubleValue], [array[2] doubleValue]);
CLLocationCoordinate2D sw = CLLocationCoordinate2DMake([array[1] doubleValue], [array[0] doubleValue]);
_boundingBox = [[CSBoundingBox alloc] initWithNorthEastCoordinate:ne southWestCoordinate:sw];
}
}
- (NSArray *)JSONObjectForBoundingBox {
if (_boundingBox == nil) {
return nil;
}
return @[
[NSNumber numberWithDouble:_boundingBox.southWest.coordinate.longitude],
[NSNumber numberWithDouble:_boundingBox.southWest.coordinate.latitude],
[NSNumber numberWithDouble:_boundingBox.northEast.coordinate.longitude],
[NSNumber numberWithDouble:_boundingBox.northEast.coordinate.latitude]
];
+ (NSDictionary *)JSONKeyPathsByPropertyKey {
return @{
@"points": @"geometry.coordinates",
@"boundingBox": @"bbox",
@"distance": @"distance",
@"time": @"time",
@"instructions": @"instructions"
};
}
- (void)setPointsWithNSArray:(NSArray *)array {
NSMutableArray *points = [NSMutableArray arrayWithCapacity:array.count];
for (NSArray *item in array) {
CLLocation *location = [[CLLocation alloc] initWithLatitude:[item[1] doubleValue] longitude:[item[0] doubleValue]];
[points addObject:location];
}
_points = [points copy];
+ (NSValueTransformer *)boundingBoxJSONTransformer {
return [MTLValueTransformer transformerUsingForwardBlock:^id(NSArray* array, BOOL *success, NSError *__autoreleasing *error) {
if (!array || array.count != 4) {
return nil;
}
CLLocationCoordinate2D ne = CLLocationCoordinate2DMake([array[3] doubleValue], [array[2] doubleValue]);
CLLocationCoordinate2D sw = CLLocationCoordinate2DMake([array[1] doubleValue], [array[0] doubleValue]);
return [[CSBoundingBox alloc] initWithNorthEastCoordinate:ne southWestCoordinate:sw];
} reverseBlock:^id(CSBoundingBox *bb, BOOL *success, NSError *__autoreleasing *error) {
if (!bb) {
return nil;
}
return @[
[NSNumber numberWithDouble:bb.southWest.coordinate.longitude],
[NSNumber numberWithDouble:bb.southWest.coordinate.latitude],
[NSNumber numberWithDouble:bb.northEast.coordinate.longitude],
[NSNumber numberWithDouble:bb.northEast.coordinate.latitude]
];
}];
}
- (NSArray *)JSONObjectForPoints {
if (_points == nil) {
return nil;
}
NSMutableArray *coordinates = [NSMutableArray arrayWithCapacity:_points.count];
for (CLLocation *item in _points) {
NSMutableArray *itemArray = [NSMutableArray arrayWithCapacity:2];
[itemArray addObject:[NSNumber numberWithDouble:item.coordinate.longitude]];
[itemArray addObject:[NSNumber numberWithDouble:item.coordinate.latitude]];
+ (NSValueTransformer *)pointsJSONTransformer {
return [MTLValueTransformer transformerUsingForwardBlock:^id(NSArray* array, BOOL *success, NSError *__autoreleasing *error) {
NSMutableArray *points = [NSMutableArray arrayWithCapacity:array.count];
for (NSArray *item in array) {
CLLocation *location = [[CLLocation alloc] initWithLatitude:[item[1] doubleValue] longitude:[item[0] doubleValue]];
[points addObject:location];
}
return [points copy];
} reverseBlock:^id(NSArray *points, BOOL *success, NSError *__autoreleasing *error) {
if (points == nil) {
return nil;
}
NSMutableArray *coordinates = [NSMutableArray arrayWithCapacity:points.count];
for (CLLocation *item in points) {
NSMutableArray *itemArray = [NSMutableArray arrayWithCapacity:2];
[itemArray addObject:[NSNumber numberWithDouble:item.coordinate.longitude]];
[itemArray addObject:[NSNumber numberWithDouble:item.coordinate.latitude]];
[coordinates addObject:itemArray.copy];
}
[coordinates addObject:itemArray.copy];
}
return [coordinates copy];
return [coordinates copy];
}];
}
+ (JSONKeyMapper *)keyMapper {
NSDictionary *map = @{
@"points": @"geometry.coordinates",
@"boundingBox": @"bbox"
};
return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:map];
+ (NSValueTransformer *)instructionsJSONTransformer {
return [MTLJSONAdapter arrayTransformerWithModelClass:[CSRouteInstruction class]];
}
@end
......@@ -5,10 +5,8 @@
// Created by Saeed Taheri on 1/13/18.
//
#import <JSONModel/JSONModel.h>
@import CoreLocation;
@protocol CSRouteInstruction;
#import <Mantle/Mantle.h>
#import <CoreLocation/CoreLocation.h>
typedef NS_ENUM(NSUInteger, CSInstructionSign) {
CSInstructionSignKeepLeft = -7,
......@@ -28,7 +26,7 @@ typedef NS_ENUM(NSUInteger, CSInstructionSign) {
/**
* Verbal representation of a route section in routing.
*/
@interface CSRouteInstruction : JSONModel
@interface CSRouteInstruction: MTLModel <MTLJSONSerializing>
/**
Distance in a route section in meters using car profile.
......
......@@ -13,12 +13,15 @@
return _time / 1000;
}
+ (JSONKeyMapper *)keyMapper {
NSDictionary *map = @{
@"streetName": @"street_name"
};
return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:map];
+ (NSDictionary *)JSONKeyPathsByPropertyKey {
return @{
@"distance": @"distance",
@"sign": @"sign",
@"time": @"time",
@"interval": @"interval",
@"text": @"text",
@"streetName": @"street_name"
};
}
@end
......@@ -6,13 +6,13 @@
//
#import <Foundation/Foundation.h>
@import CoreLocation;
#import <CoreLocation/CoreLocation.h>
/**
A wrapper class consisting of a source and a destination for using in a Directions or Distance request.
*/
@interface CSRoutePair : NSObject
@interface CSRoutePair: NSObject
/**
......
......@@ -203,6 +203,7 @@
6003F587195388D20070C39A /* Frameworks */,
6003F588195388D20070C39A /* Resources */,
0CBBC485A1B770CB94C1D22B /* [CP] Embed Pods Frameworks */,
F4A1E7639F2E39A8CCDEFE6F /* [CP] Copy Pods Resources */,
);
buildRules = (
);
......@@ -271,15 +272,13 @@
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-CedarMaps_Example/Pods-CedarMaps_Example-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/CedarMaps/CedarMaps.framework",
"${BUILT_PRODUCTS_DIR}/JSONModel/JSONModel.framework",
"${BUILT_PRODUCTS_DIR}/Mantle/Mantle.framework",
"${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/Mapbox.framework",
"${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/Mapbox.framework.dSYM",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CedarMaps.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/JSONModel.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Mantle.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Mapbox.framework",
"${DWARF_DSYM_FOLDER_PATH}/Mapbox.framework.dSYM",
);
......@@ -306,6 +305,24 @@
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
F4A1E7639F2E39A8CCDEFE6F /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-CedarMaps_Example/Pods-CedarMaps_Example-resources.sh",
"${PODS_CONFIGURATION_BUILD_DIR}/CedarMaps/CedarMaps.bundle",
);
name = "[CP] Copy Pods Resources";
outputPaths = (
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/CedarMaps.bundle",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-CedarMaps_Example/Pods-CedarMaps_Example-resources.sh\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
......
......@@ -15,9 +15,9 @@
{
[[CSMapKit sharedMapKit] setCredentialsWithClientID:@"YOUR_CLIENT_ID" clientSecret:@"YOUR_CLIENT_SECRET"];
[[CSMapKit sharedMapKit] prepareMapTiles:^(BOOL isReady, NSError * _Nullable error) {
[[CSMapKit sharedMapKit] prepareMapTiles:^(BOOL isReady, NSError * _Nullable error) {
}];
return YES;
......
PODS:
- CedarMaps (3.0.0):
- JSONModel (~> 1.7)
- Mantle (~> 2.1)
- Mapbox-iOS-SDK (~> 4.0)
- JSONModel (1.7.0)
- Mantle (2.1.0):
- Mantle/extobjc (= 2.1.0)
- Mantle/extobjc (2.1.0)
- Mapbox-iOS-SDK (4.0.0)
DEPENDENCIES:
- CedarMaps (from `../`)
SPEC REPOS:
https://github.com/CocoaPods/Specs.git:
- JSONModel
https://github.com/cocoapods/specs.git:
- Mantle
- Mapbox-iOS-SDK
EXTERNAL SOURCES:
......@@ -18,10 +20,10 @@ EXTERNAL SOURCES:
:path: "../"
SPEC CHECKSUMS:
CedarMaps: 44f2a75fe9f0cdea435954d3dd3bbf2ea8935629
JSONModel: 840bc0fcffb24b8454d2c026bf26fea454b8e98d
CedarMaps: d8d7b32c66674c469672bc42d761a8bee2ab3d42
Mantle: 2fa750afa478cd625a94230fbf1c13462f29395b
Mapbox-iOS-SDK: 271754e96eb4434ba1b0a8c68432e1ea26fe9841
PODFILE CHECKSUM: ad43b9956cf1f58bff64834a5e21f42f322108fa
COCOAPODS: 1.5.0
COCOAPODS: 1.5.2
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment