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 @@ ...@@ -8,7 +8,7 @@
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = 'CedarMaps' s.name = 'CedarMaps'
s.version = '3.0.0' s.version = '3.0.1'
s.summary = 'CedarMaps iOS SDK' s.summary = 'CedarMaps iOS SDK'
# This description is used to generate tags and improve search results. # This description is used to generate tags and improve search results.
...@@ -43,5 +43,5 @@ Pod::Spec.new do |s| ...@@ -43,5 +43,5 @@ Pod::Spec.new do |s|
s.public_header_files = 'CedarMaps/Classes/**/*.h' s.public_header_files = 'CedarMaps/Classes/**/*.h'
s.dependency 'Mapbox-iOS-SDK', '~> 4.0' s.dependency 'Mapbox-iOS-SDK', '~> 4.0'
s.dependency 'JSONModel', '~> 1.7' s.dependency 'Mantle', '~> 2.1'
end end
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
static NSString * _Nonnull const kCedarMapsAccessTokenIsReadeyNotification = @"kCedarMapsAccessTokenIsReadeyNotification"; 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 *clientID;
@property (nonatomic, strong, readonly, nullable) NSString *clientSecret; @property (nonatomic, strong, readonly, nullable) NSString *clientSecret;
......
...@@ -6,15 +6,13 @@ ...@@ -6,15 +6,13 @@
// //
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <JSONModel/JSONModel.h> #import <Mantle/Mantle.h>
@import CoreLocation; #import <CoreLocation/CoreLocation.h>
@protocol CSBoundingBox;
/** /**
* The class used for creating a rectangular region bu specifying south west and north east coordinates. * 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 @@ ...@@ -18,37 +18,32 @@
return self; return self;
} }
+ (JSONKeyMapper *)keyMapper { + (NSDictionary *)JSONKeyPathsByPropertyKey {
NSDictionary *map = @{ @"northEast": @"ne", return @{
@"southWest": @"sw" @"northEast": @"ne",
}; @"southWest": @"sw"
};
return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:map];
} }
- (void)setNorthEastWithString:(NSString *)string { + (NSValueTransformer *)northEastJSONTransformer {
_northEast = [self CLLocationFromNSString:string]; 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 { + (NSValueTransformer *)southWestJSONTransformer {
return [self JSONObjectFromCLLocation:_northEast]; 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 { + (CLLocation *)CLLocationFromNSString:(NSString *)string {
_southWest = [self CLLocationFromNSString:string];
}
- (NSString *)JSONObjectForSouthWest {
return [self JSONObjectFromCLLocation:_southWest];
}
- (CLLocation *)CLLocationFromNSString:(NSString *)string {
NSArray *comps = [string componentsSeparatedByString:@","]; NSArray *comps = [string componentsSeparatedByString:@","];
return [[CLLocation alloc] initWithLatitude:[comps[0] doubleValue] longitude:[comps[1] doubleValue]]; 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 @end
...@@ -5,12 +5,12 @@ ...@@ -5,12 +5,12 @@
// Created by Saeed Taheri on 10/25/17. // Created by Saeed Taheri on 10/25/17.
// //
#import <JSONModel/JSONModel.h> #import <Mantle/Mantle.h>
#import "CSRoute.h" #import "CSRoute.h"
@interface CSDirectionResponse : JSONModel @interface CSDirectionResponse : MTLModel <MTLJSONSerializing>
@property (nonatomic, strong, nonnull) NSString *status; @property (nonatomic, strong, nonnull) NSString *status;
@property (nonatomic, strong, nullable) NSArray<CSRoute *> <CSRoute, Optional> *routes; @property (nonatomic, strong, nullable) NSArray<CSRoute *> *routes;
@end @end
...@@ -9,11 +9,15 @@ ...@@ -9,11 +9,15 @@
@implementation CSDirectionResponse @implementation CSDirectionResponse
+ (JSONKeyMapper *)keyMapper { + (NSDictionary *)JSONKeyPathsByPropertyKey {
NSDictionary *map = @{ @"routes": @"result.routes" return @{
}; @"routes": @"result.routes",
@"status": @"status"
return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:map]; };
}
+ (NSValueTransformer *)routesJSONTransformer {
return [MTLJSONAdapter arrayTransformerWithModelClass:[CSRoute class]];
} }
@end @end
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#define CEDARMAPS_RESPONSE_PARSING_ERROR @"Response Parsing Error" #define CEDARMAPS_RESPONSE_PARSING_ERROR @"Response Parsing Error"
#define CEDARMAPS_UNKNOWN_ERROR @"Unknown Error" #define CEDARMAPS_UNKNOWN_ERROR @"Unknown Error"
@interface CSError : NSError @interface CSError: NSError
+ (nonnull NSError *)errorWithDescription:(nonnull NSString *)errorDescription; + (nonnull NSError *)errorWithDescription:(nonnull NSString *)errorDescription;
......
...@@ -5,17 +5,31 @@ ...@@ -5,17 +5,31 @@
// Created by Saeed Taheri on 10/24/17. // Created by Saeed Taheri on 10/24/17.
// //
#import <JSONModel/JSONModel.h> #import <Mantle/Mantle.h>
#import "CSRegion.h" #import "CSRegion.h"
@protocol CSForwardGeocodePlacemark; #pragma mark Components
@class CSForwardGeocodeComponent;
/**
* 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 * 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. * information such as the province, city, and street address.
*/ */
@interface CSForwardGeocodePlacemark: JSONModel @interface CSForwardGeocodePlacemark: MTLModel <MTLJSONSerializing>
/** /**
...@@ -33,7 +47,7 @@ ...@@ -33,7 +47,7 @@
/** /**
English name of the result. English name of the result.
*/ */
@property (nonatomic, strong, nullable) NSString<Optional> *nameEn; @property (nonatomic, strong, nullable) NSString *nameEn;
/** /**
...@@ -45,7 +59,7 @@ ...@@ -45,7 +59,7 @@
/** /**
A simple generated address from components field. A simple generated address from components field.
*/ */
@property (nonatomic, strong, nullable) NSString<Optional> *address; @property (nonatomic, strong, nullable) NSString *address;
/** /**
...@@ -57,7 +71,7 @@ ...@@ -57,7 +71,7 @@
/** /**
Geometric region of the result. Geometric region of the result.
*/ */
@property (nonatomic, strong, nullable) CSRegion<Optional> *region; @property (nonatomic, strong, nullable) CSRegion *region;
@end @end
...@@ -73,19 +87,3 @@ typedef NS_OPTIONS(NSUInteger, CSPlacemarkType) { ...@@ -73,19 +87,3 @@ typedef NS_OPTIONS(NSUInteger, CSPlacemarkType) {
CSPlacemarkTypeLocality = 1 << 5, CSPlacemarkTypeLocality = 1 << 5,
}; };
NSString* _Nonnull stringValueForPlacemarkType(CSPlacemarkType type); 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 @@ ...@@ -9,19 +9,36 @@
@implementation CSForwardGeocodePlacemark @implementation CSForwardGeocodePlacemark
+ (JSONKeyMapper *)keyMapper { + (NSDictionary *)JSONKeyPathsByPropertyKey {
NSDictionary *map = @{ @"identifier": @"id", return @{
@"nameEn": @"name_en", @"identifier": @"id",
@"region": @"location" @"name": @"name",
}; @"nameEn": @"name_en",
@"type": @"type",
return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:map]; @"region": @"location",
@"address": @"address",
@"components": @"components"
};
}
+ (NSValueTransformer *)regionJSONTransformer {
return [MTLJSONAdapter dictionaryTransformerWithModelClass:[CSRegion class]];
} }
@end @end
@implementation CSForwardGeocodeComponent @implementation CSForwardGeocodeComponent
+ (NSDictionary *)JSONKeyPathsByPropertyKey {
return @{
@"country": @"country",
@"province": @"province",
@"city": @"city",
@"districts": @"districts",
@"localities": @"localities"
};
}
@end @end
NSString* stringValueForPlacemarkType(CSPlacemarkType type) { NSString* stringValueForPlacemarkType(CSPlacemarkType type) {
......
...@@ -5,12 +5,12 @@ ...@@ -5,12 +5,12 @@
// Created by Saeed Taheri on 10/24/17. // Created by Saeed Taheri on 10/24/17.
// //
#import <JSONModel/JSONModel.h> #import <Mantle/Mantle.h>
#import "CSForwardGeocodePlacemark.h" #import "CSForwardGeocodePlacemark.h"
@interface CSForwardGeocodeResponse : JSONModel @interface CSForwardGeocodeResponse: MTLModel <MTLJSONSerializing>
@property (nonatomic, strong, nonnull) NSString *status; @property (nonatomic, strong, nonnull) NSString *status;
@property (nonatomic, strong, nullable) NSArray<CSForwardGeocodePlacemark *> <CSForwardGeocodePlacemark, Optional> *results; @property (nonatomic, strong, nullable) NSArray<CSForwardGeocodePlacemark *> *results;
@end @end
...@@ -9,4 +9,15 @@ ...@@ -9,4 +9,15 @@
@implementation CSForwardGeocodeResponse @implementation CSForwardGeocodeResponse
+ (NSDictionary *)JSONKeyPathsByPropertyKey {
return @{
@"results": @"results",
@"status": @"status"
};
}
+ (NSValueTransformer *)resultsJSONTransformer {
return [MTLJSONAdapter arrayTransformerWithModelClass:[CSForwardGeocodePlacemark class]];
}
@end @end
@import CoreLocation; #import <CoreLocation/CoreLocation.h>
#import "CSForwardGeocodePlacemark.h" #import "CSForwardGeocodePlacemark.h"
#import "CSReverseGeocodePlacemark.h" #import "CSReverseGeocodePlacemark.h"
#import "CSRoute.h" #import "CSRoute.h"
......
...@@ -140,7 +140,13 @@ typedef void (^CSNetworkResponseCompletionHandler)(NSData * _Nullable data, NSUR ...@@ -140,7 +140,13 @@ typedef void (^CSNetworkResponseCompletionHandler)(NSData * _Nullable data, NSUR
} else if (data != nil) { } else if (data != nil) {
NSError *parsingError; 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) { if (parsingError != nil) {
completionHandler(nil, parsingError); completionHandler(nil, parsingError);
...@@ -279,7 +285,13 @@ typedef void (^CSNetworkResponseCompletionHandler)(NSData * _Nullable data, NSUR ...@@ -279,7 +285,13 @@ typedef void (^CSNetworkResponseCompletionHandler)(NSData * _Nullable data, NSUR
} else if (data != nil) { } else if (data != nil) {
NSError *parsingError; 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) { if (parsingError != nil) {
completionHandler(nil, parsingError); completionHandler(nil, parsingError);
...@@ -361,7 +373,13 @@ typedef enum { ...@@ -361,7 +373,13 @@ typedef enum {
} else if (data != nil) { } else if (data != nil) {
NSError *parsingError; 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) { if (parsingError != nil) {
completionHandler(nil, parsingError); completionHandler(nil, parsingError);
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
// //
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
@import CoreLocation; #import <CoreLocation/CoreLocation.h>
/** /**
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
// //
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
@import CoreLocation; #import <CoreLocation/CoreLocation.h>
/** /**
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import "CSMapSnapshotMarker.h" #import "CSMapSnapshotMarker.h"
@import CoreLocation; #import <CoreLocation/CoreLocation.h>
/** /**
......
...@@ -5,16 +5,15 @@ ...@@ -5,16 +5,15 @@
// Created by Saeed Taheri on 10/24/17. // Created by Saeed Taheri on 10/24/17.
// //
#import <JSONModel/JSONModel.h> #import <Mantle/Mantle.h>
#import <CoreLocation/CoreLocation.h>
#import "CSBoundingBox.h" #import "CSBoundingBox.h"
@import CoreLocation;
/** /**
* *
* Geometric region of a Forward Geocode result. * Geometric region of a Forward Geocode result.
*/ */
@interface CSRegion: JSONModel @interface CSRegion: MTLModel <MTLJSONSerializing>
/** /**
......
...@@ -9,40 +9,40 @@ ...@@ -9,40 +9,40 @@
@implementation CSRegion @implementation CSRegion
+ (JSONKeyMapper *)keyMapper { + (NSDictionary *)JSONKeyPathsByPropertyKey {
NSDictionary *map = @{ @"boundingBox": @"bb", return @{
}; @"boundingBox": @"bb",
@"center": @"center"
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]
}; };
} }
- (void)setCenterWithNSString:(NSString *)string { + (NSValueTransformer *)boundingBoxJSONTransformer {
NSArray *comps = [string componentsSeparatedByString:@","]; return [MTLValueTransformer transformerUsingForwardBlock:^id(NSDictionary* dict, BOOL *success, NSError *__autoreleasing *error) {
_center = [[CLLocation alloc] initWithLatitude:[comps[0] doubleValue] longitude:[comps[1] doubleValue]]; 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 { + (NSValueTransformer *)centerJSONTransformer {
if (_center == nil) { return [MTLValueTransformer transformerUsingForwardBlock:^id(NSString* string, BOOL *success, NSError *__autoreleasing *error) {
return nil; NSArray *comps = [string componentsSeparatedByString:@","];
} return [[CLLocation alloc] initWithLatitude:[comps[0] doubleValue] longitude:[comps[1] doubleValue]];
return [NSString stringWithFormat:@"%f,%f", _center.coordinate.latitude, _center.coordinate.longitude]; } 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 @end
...@@ -5,66 +5,64 @@ ...@@ -5,66 +5,64 @@
// Created by Saeed Taheri on 10/24/17. // Created by Saeed Taheri on 10/24/17.
// //
#import <JSONModel/JSONModel.h> #import <Mantle/Mantle.h>
@class CSTrafficZone; @class CSTrafficZone;
@class CSReverseGeocodeComponent; @class CSReverseGeocodeComponent;
@protocol CSReverseGeocodeComponent;
/** /**
* Represents placemark data for a geographic location in a reverse geocode request. Placemark data can be * 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. * information such as the province, city, and street address.
*/ */
@interface CSReverseGeocodePlacemark: JSONModel @interface CSReverseGeocodePlacemark: MTLModel <MTLJSONSerializing>
/** /**
Address for the result. Address for the result.
*/ */
@property (nonatomic, strong, nullable) NSString<Optional> *address; @property (nonatomic, strong, nullable) NSString *address;
/** /**
Locality name for the result. Locality name for the result.
*/ */
@property (nonatomic, strong, nullable) NSString<Optional> *locality; @property (nonatomic, strong, nullable) NSString *locality;
/** /**
District name for the result. 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. 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. City name for the result.
*/ */
@property (nonatomic, strong, nullable) NSString<Optional> *city; @property (nonatomic, strong, nullable) NSString *city;
/** /**
Province name for the result. Province name for the result.
*/ */
@property (nonatomic, strong, nullable) NSString<Optional> *province; @property (nonatomic, strong, nullable) NSString *province;
/** /**
Traffic zone information for the result. 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. Detailed address components for the result.
*/ */
@property (nonatomic, strong, nullable) NSArray<CSReverseGeocodeComponent *> <CSReverseGeocodeComponent, Optional> *components; @property (nonatomic, strong, nullable) NSArray<CSReverseGeocodeComponent *> *components;
@end @end
...@@ -76,13 +74,13 @@ typedef void (^CSReverseGeocodeCompletionHandler)(CSReverseGeocodePlacemark* __n ...@@ -76,13 +74,13 @@ typedef void (^CSReverseGeocodeCompletionHandler)(CSReverseGeocodePlacemark* __n
/** /**
* Traffic zone information for a Reverse Geocode response * Traffic zone information for a Reverse Geocode response
*/ */
@interface CSTrafficZone: JSONModel @interface CSTrafficZone: MTLModel <MTLJSONSerializing>
/** /**
Name of the Traffic Zone. 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 ...@@ -103,19 +101,19 @@ typedef void (^CSReverseGeocodeCompletionHandler)(CSReverseGeocodePlacemark* __n
/** /**
* Detailed components of a Reverse Geocode response * Detailed components of a Reverse Geocode response
*/ */
@interface CSReverseGeocodeComponent: JSONModel @interface CSReverseGeocodeComponent: MTLModel <MTLJSONSerializing>
/** /**
Short name of the component for a result 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 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 @@ ...@@ -9,11 +9,25 @@
@implementation CSReverseGeocodePlacemark @implementation CSReverseGeocodePlacemark
+ (JSONKeyMapper *)keyMapper { + (NSDictionary *)JSONKeyPathsByPropertyKey {
NSDictionary *map = @{ @"trafficZone": @"traffic_zone" return @{
}; @"components": @"components",
@"address": @"address",
return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:map]; @"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 @end
...@@ -22,12 +36,12 @@ ...@@ -22,12 +36,12 @@
@implementation CSTrafficZone @implementation CSTrafficZone
+ (JSONKeyMapper *)keyMapper { + (NSDictionary *)JSONKeyPathsByPropertyKey {
NSDictionary *map = @{ @"inEvenOdd": @"in_evenodd", return @{
@"inCentral": @"in_central" @"name": @"name",
}; @"inCentral": @"in_central",
@"inEvenOdd": @"in_evenodd"
return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:map]; };
} }
@end @end
...@@ -36,12 +50,12 @@ ...@@ -36,12 +50,12 @@
@implementation CSReverseGeocodeComponent @implementation CSReverseGeocodeComponent
+ (JSONKeyMapper *)keyMapper { + (NSDictionary *)JSONKeyPathsByPropertyKey {
NSDictionary *map = @{ @"longName": @"long_name", return @{
@"shortName": @"short_name" @"longName": @"long_name",
}; @"shortName": @"short_name",
@"type": @"type"
return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:map]; };
} }
@end @end
...@@ -5,12 +5,12 @@ ...@@ -5,12 +5,12 @@
// Created by Saeed Taheri on 10/24/17. // Created by Saeed Taheri on 10/24/17.
// //
#import <JSONModel/JSONModel.h> #import <Mantle/Mantle.h>
#import "CSReverseGeocodePlacemark.h" #import "CSReverseGeocodePlacemark.h"
@interface CSReverseGeocodeResponse : JSONModel @interface CSReverseGeocodeResponse: MTLModel <MTLJSONSerializing>
@property (nonatomic, strong, nonnull) NSString *status; @property (nonatomic, strong, nonnull) NSString *status;
@property (nonatomic, strong, nullable) CSReverseGeocodePlacemark<Optional> *result; @property (nonatomic, strong, nullable) CSReverseGeocodePlacemark *result;
@end @end
...@@ -9,4 +9,15 @@ ...@@ -9,4 +9,15 @@
@implementation CSReverseGeocodeResponse @implementation CSReverseGeocodeResponse
+ (NSDictionary *)JSONKeyPathsByPropertyKey {
return @{
@"result": @"result",
@"status": @"status"
};
}
+ (NSValueTransformer *)resultsJSONTransformer {
return [MTLJSONAdapter dictionaryTransformerWithModelClass:[CSReverseGeocodePlacemark class]];
}
@end @end
...@@ -5,16 +5,14 @@ ...@@ -5,16 +5,14 @@
// Created by Saeed Taheri on 10/25/17. // Created by Saeed Taheri on 10/25/17.
// //
#import <JSONModel/JSONModel.h> #import <Mantle/Mantle.h>
#import "CSBoundingBox.h" #import "CSBoundingBox.h"
#import "CSRouteInstruction.h" #import "CSRouteInstruction.h"
@protocol CSRoute;
/** /**
* A CSRoute object shows direction and distance information. * A CSRoute object shows direction and distance information.
*/ */
@interface CSRoute: JSONModel @interface CSRoute: MTLModel <MTLJSONSerializing>
/** /**
...@@ -38,12 +36,12 @@ ...@@ -38,12 +36,12 @@
/** /**
The location points which make a route. 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. * Verbal representation of the route.
*/ */
@property (nonatomic, strong, nullable) NSArray<CSRouteInstruction *> <Optional, CSRouteInstruction> *instructions; @property (nonatomic, strong, nullable) NSArray<CSRouteInstruction *> *instructions;
@end @end
......
...@@ -13,62 +13,68 @@ ...@@ -13,62 +13,68 @@
return _time / 1000; return _time / 1000;
} }
- (void)setBoundingBoxWithNSArray:(NSArray *)array { + (NSDictionary *)JSONKeyPathsByPropertyKey {
if (array && array.count == 4) { return @{
CLLocationCoordinate2D ne = CLLocationCoordinate2DMake([array[3] doubleValue], [array[2] doubleValue]); @"points": @"geometry.coordinates",
CLLocationCoordinate2D sw = CLLocationCoordinate2DMake([array[1] doubleValue], [array[0] doubleValue]); @"boundingBox": @"bbox",
_boundingBox = [[CSBoundingBox alloc] initWithNorthEastCoordinate:ne southWestCoordinate:sw]; @"distance": @"distance",
} @"time": @"time",
} @"instructions": @"instructions"
};
- (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]
];
} }
- (void)setPointsWithNSArray:(NSArray *)array { + (NSValueTransformer *)boundingBoxJSONTransformer {
NSMutableArray *points = [NSMutableArray arrayWithCapacity:array.count]; return [MTLValueTransformer transformerUsingForwardBlock:^id(NSArray* array, BOOL *success, NSError *__autoreleasing *error) {
if (!array || array.count != 4) {
for (NSArray *item in array) { return nil;
CLLocation *location = [[CLLocation alloc] initWithLatitude:[item[1] doubleValue] longitude:[item[0] doubleValue]]; }
[points addObject:location]; 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];
_points = [points copy]; } 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 { + (NSValueTransformer *)pointsJSONTransformer {
if (_points == nil) { return [MTLValueTransformer transformerUsingForwardBlock:^id(NSArray* array, BOOL *success, NSError *__autoreleasing *error) {
return nil; NSMutableArray *points = [NSMutableArray arrayWithCapacity:array.count];
}
for (NSArray *item in array) {
NSMutableArray *coordinates = [NSMutableArray arrayWithCapacity:_points.count]; CLLocation *location = [[CLLocation alloc] initWithLatitude:[item[1] doubleValue] longitude:[item[0] doubleValue]];
[points addObject:location];
for (CLLocation *item in _points) { }
NSMutableArray *itemArray = [NSMutableArray arrayWithCapacity:2];
[itemArray addObject:[NSNumber numberWithDouble:item.coordinate.longitude]]; return [points copy];
[itemArray addObject:[NSNumber numberWithDouble:item.coordinate.latitude]]; } 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 { + (NSValueTransformer *)instructionsJSONTransformer {
NSDictionary *map = @{ return [MTLJSONAdapter arrayTransformerWithModelClass:[CSRouteInstruction class]];
@"points": @"geometry.coordinates",
@"boundingBox": @"bbox"
};
return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:map];
} }
@end @end
...@@ -5,10 +5,8 @@ ...@@ -5,10 +5,8 @@
// Created by Saeed Taheri on 1/13/18. // Created by Saeed Taheri on 1/13/18.
// //
#import <JSONModel/JSONModel.h> #import <Mantle/Mantle.h>
@import CoreLocation; #import <CoreLocation/CoreLocation.h>
@protocol CSRouteInstruction;
typedef NS_ENUM(NSUInteger, CSInstructionSign) { typedef NS_ENUM(NSUInteger, CSInstructionSign) {
CSInstructionSignKeepLeft = -7, CSInstructionSignKeepLeft = -7,
...@@ -28,7 +26,7 @@ typedef NS_ENUM(NSUInteger, CSInstructionSign) { ...@@ -28,7 +26,7 @@ typedef NS_ENUM(NSUInteger, CSInstructionSign) {
/** /**
* Verbal representation of a route section in routing. * 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. Distance in a route section in meters using car profile.
......
...@@ -13,12 +13,15 @@ ...@@ -13,12 +13,15 @@
return _time / 1000; return _time / 1000;
} }
+ (JSONKeyMapper *)keyMapper { + (NSDictionary *)JSONKeyPathsByPropertyKey {
NSDictionary *map = @{ return @{
@"streetName": @"street_name" @"distance": @"distance",
}; @"sign": @"sign",
@"time": @"time",
return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:map]; @"interval": @"interval",
@"text": @"text",
@"streetName": @"street_name"
};
} }
@end @end
...@@ -6,13 +6,13 @@ ...@@ -6,13 +6,13 @@
// //
#import <Foundation/Foundation.h> #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. 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 @@ ...@@ -203,6 +203,7 @@
6003F587195388D20070C39A /* Frameworks */, 6003F587195388D20070C39A /* Frameworks */,
6003F588195388D20070C39A /* Resources */, 6003F588195388D20070C39A /* Resources */,
0CBBC485A1B770CB94C1D22B /* [CP] Embed Pods Frameworks */, 0CBBC485A1B770CB94C1D22B /* [CP] Embed Pods Frameworks */,
F4A1E7639F2E39A8CCDEFE6F /* [CP] Copy Pods Resources */,
); );
buildRules = ( buildRules = (
); );
...@@ -271,15 +272,13 @@ ...@@ -271,15 +272,13 @@
); );
inputPaths = ( inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-CedarMaps_Example/Pods-CedarMaps_Example-frameworks.sh", "${SRCROOT}/Pods/Target Support Files/Pods-CedarMaps_Example/Pods-CedarMaps_Example-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/CedarMaps/CedarMaps.framework", "${BUILT_PRODUCTS_DIR}/Mantle/Mantle.framework",
"${BUILT_PRODUCTS_DIR}/JSONModel/JSONModel.framework",
"${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/Mapbox.framework", "${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/Mapbox.framework",
"${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/Mapbox.framework.dSYM", "${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/Mapbox.framework.dSYM",
); );
name = "[CP] Embed Pods Frameworks"; name = "[CP] Embed Pods Frameworks";
outputPaths = ( outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CedarMaps.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Mantle.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/JSONModel.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Mapbox.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Mapbox.framework",
"${DWARF_DSYM_FOLDER_PATH}/Mapbox.framework.dSYM", "${DWARF_DSYM_FOLDER_PATH}/Mapbox.framework.dSYM",
); );
...@@ -306,6 +305,24 @@ ...@@ -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"; 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; 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 */ /* End PBXShellScriptBuildPhase section */
/* Begin PBXSourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */
......
...@@ -15,9 +15,9 @@ ...@@ -15,9 +15,9 @@
{ {
[[CSMapKit sharedMapKit] setCredentialsWithClientID:@"YOUR_CLIENT_ID" clientSecret:@"YOUR_CLIENT_SECRET"]; [[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; return YES;
......
PODS: PODS:
- CedarMaps (3.0.0): - CedarMaps (3.0.0):
- JSONModel (~> 1.7) - Mantle (~> 2.1)
- Mapbox-iOS-SDK (~> 4.0) - 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) - Mapbox-iOS-SDK (4.0.0)
DEPENDENCIES: DEPENDENCIES:
- CedarMaps (from `../`) - CedarMaps (from `../`)
SPEC REPOS: SPEC REPOS:
https://github.com/CocoaPods/Specs.git: https://github.com/cocoapods/specs.git:
- JSONModel - Mantle
- Mapbox-iOS-SDK - Mapbox-iOS-SDK
EXTERNAL SOURCES: EXTERNAL SOURCES:
...@@ -18,10 +20,10 @@ EXTERNAL SOURCES: ...@@ -18,10 +20,10 @@ EXTERNAL SOURCES:
:path: "../" :path: "../"
SPEC CHECKSUMS: SPEC CHECKSUMS:
CedarMaps: 44f2a75fe9f0cdea435954d3dd3bbf2ea8935629 CedarMaps: d8d7b32c66674c469672bc42d761a8bee2ab3d42
JSONModel: 840bc0fcffb24b8454d2c026bf26fea454b8e98d Mantle: 2fa750afa478cd625a94230fbf1c13462f29395b
Mapbox-iOS-SDK: 271754e96eb4434ba1b0a8c68432e1ea26fe9841 Mapbox-iOS-SDK: 271754e96eb4434ba1b0a8c68432e1ea26fe9841
PODFILE CHECKSUM: ad43b9956cf1f58bff64834a5e21f42f322108fa 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