Skip to content

Commit

Permalink
Add backwards-compatible nullability annotations and generics
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler Fox authored and Tyler Fox committed Aug 7, 2015
1 parent acc481e commit 746743e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
3 changes: 3 additions & 0 deletions LocationManager/INTULocationManager/INTULocationManager.h
Expand Up @@ -32,6 +32,8 @@ FOUNDATION_EXPORT double INTULocationManagerVersionNumber;
FOUNDATION_EXPORT const unsigned char INTULocationManagerVersionString[];


__INTU_ASSUME_NONNULL_BEGIN

/**
An abstraction around CLLocationManager that provides a block-based asynchronous API for obtaining the device's location.
INTULocationManager automatically starts and stops system location services as needed to minimize battery drain.
Expand Down Expand Up @@ -98,3 +100,4 @@ FOUNDATION_EXPORT const unsigned char INTULocationManagerVersionString[];

@end

__INTU_ASSUME_NONNULL_END
6 changes: 3 additions & 3 deletions LocationManager/INTULocationManager/INTULocationManager.m
Expand Up @@ -56,7 +56,7 @@ @interface INTULocationManager () <CLLocationManagerDelegate, INTULocationReques

// An array of pending location requests in the form:
// @[ INTULocationRequest *locationRequest1, INTULocationRequest *locationRequest2, ... ]
@property (nonatomic, strong) NSMutableArray *locationRequests;
@property (nonatomic, strong) __INTU_GENERICS(NSMutableArray, INTULocationRequest *) *locationRequests;

@end

Expand Down Expand Up @@ -338,7 +338,7 @@ - (void)processLocationRequests
CLLocation *mostRecentLocation = self.currentLocation;

// Keep a separate array of location requests to complete to avoid modifying the locationRequests property while iterating over it
NSMutableArray *locationRequestsToComplete = [NSMutableArray array];
__INTU_GENERICS(NSMutableArray, INTULocationRequest *) *locationRequestsToComplete = [NSMutableArray array];

for (INTULocationRequest *locationRequest in self.locationRequests) {
if (locationRequest.hasTimedOut) {
Expand Down Expand Up @@ -380,7 +380,7 @@ - (void)processLocationRequests
- (void)completeAllLocationRequests
{
// Iterate through a copy of the locationRequests array to avoid modifying the same array we are removing elements from
NSArray *locationRequests = [self.locationRequests copy];
__INTU_GENERICS(NSArray, INTULocationRequest *) *locationRequests = [self.locationRequests copy];
for (INTULocationRequest *locationRequest in locationRequests) {
[self completeLocationRequest:locationRequest];
}
Expand Down
8 changes: 6 additions & 2 deletions LocationManager/INTULocationManager/INTULocationRequest.h
Expand Up @@ -25,6 +25,8 @@

#import "INTULocationRequestDefines.h"

__INTU_ASSUME_NONNULL_BEGIN

@class INTULocationRequest;

/**
Expand All @@ -48,7 +50,7 @@
@interface INTULocationRequest : NSObject

/** The delegate for this location request. */
@property (nonatomic, weak) id<INTULocationRequestDelegate> delegate;
@property (nonatomic, weak, __INTU_NULLABLE) id<INTULocationRequestDelegate> delegate;
/** The request ID for this location request (set during initialization). */
@property (nonatomic, readonly) INTULocationRequestID requestID;
/** Whether this is a subscription request (desired accuracy is INTULocationAccuracyNone). */
Expand All @@ -64,7 +66,7 @@
/** Whether this location request has timed out (will also be YES if it has been completed). */
@property (nonatomic, readonly) BOOL hasTimedOut;
/** The block to execute when the location request completes. */
@property (nonatomic, copy) INTULocationRequestBlock block;
@property (nonatomic, copy, __INTU_NULLABLE) INTULocationRequestBlock block;

/** Completes the location request. */
- (void)complete;
Expand All @@ -83,3 +85,5 @@
- (CLLocationAccuracy)horizontalAccuracyThreshold;

@end

__INTU_ASSUME_NONNULL_END
16 changes: 16 additions & 0 deletions LocationManager/INTULocationManager/INTULocationRequestDefines.h
Expand Up @@ -29,6 +29,22 @@
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>

#if __has_feature(nullability)
# define __INTU_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
# define __INTU_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
# define __INTU_NULLABLE nullable
#else
# define __INTU_ASSUME_NONNULL_BEGIN
# define __INTU_ASSUME_NONNULL_END
# define __INTU_NULLABLE
#endif

#if __has_feature(objc_generics)
# define __INTU_GENERICS(type, ...) type<__VA_ARGS__>
#else
# define __INTU_GENERICS(type, ...) type
#endif

static const CLLocationAccuracy kINTUHorizontalAccuracyThresholdCity = 5000.0; // in meters
static const CLLocationAccuracy kINTUHorizontalAccuracyThresholdNeighborhood = 1000.0; // in meters
static const CLLocationAccuracy kINTUHorizontalAccuracyThresholdBlock = 100.0; // in meters
Expand Down

0 comments on commit 746743e

Please sign in to comment.