Skip to content

Instantly share code, notes, and snippets.

View JanC's full-sized avatar

Jan Chaloupecky JanC

  • N26
  • Berlin
View GitHub Profile
@nicklockwood
nicklockwood / Deprecated.md
Last active March 28, 2022 08:16
Writing Objective-C framework code that works on multiple OS versions AND can be compiled using multiple SDK versions without warnings can be a PITA. Here's my approach:

Suppose we want to add support for a new iOS 8 API in our framework that replaces an older iOS 7 API. There are a few problems we might face:

  1. The new API will crash if we call it on iOS 7
  2. The new API won't compile if we build it using the iOS 7 SDK
  3. The old API will raise a deprecation warning if built with a deployment target of iOS 8 and up

These three problems require three different technical solutions:

  1. We can avoid calling the new API on an old OS version by using runtime detection (e.g. respondsToSelector:)
  2. We can avoid compiling new APIs on old SDKs using the __IPHONE_OS_VERSION_MAX_ALLOWED macro
@jmcd
jmcd / AnnotationCoordinateUtility.m
Last active October 4, 2021 19:32
Calculate a new coordinate given a starting coordinate, bearing and distance. Objective-C
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>
#import "AnnotationCoordinateUtility.h"
@implementation AnnotationCoordinateUtility {
}
+ (void)mutateCoordinatesOfClashingAnnotations:(NSArray *)annotations {