Skip to content

Instantly share code, notes, and snippets.

@jjrscott
Last active August 29, 2015 14:01
Show Gist options
  • Save jjrscott/6861f1a012182221a5ab to your computer and use it in GitHub Desktop.
Save jjrscott/6861f1a012182221a5ab to your computer and use it in GitHub Desktop.
Macros to ensure a certain runtime level of iOS, then emit compiler warnings when the iOS Deployment Target reaches that level.
//
// JJRSMovingOn.h
//
// The MIT License (MIT)
//
// Copyright (c) 2014 John James Ralph Scott
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
#ifndef __JJRSMOVINGON__
#define __JJRSMOVINGON__
/*
These macros are for use to ensure a certain runtime level of iOS, then emit
compiler warnings when the iOS Deployment Target reaches that level.
For example:
if (ENSURE_IPHONE_7_0)
{
NSTimer *timer = ...;
timer.tolerance = 5; // - (NSTimeInterval)tolerance NS_AVAILABLE(10_9, 7_0);
}
will ensure the code is only executed on iOS 7.0 or greater. When the project's
iOS Deployment Target reaches 7.0, the code will always be executed and a compiler
warning emited until the redundant 'if' block is removed.
*/
#pragma mark - Utility macros
#define __JJRSMOVINGON_STR(v) #v
#define __JJRSMOVINGON_CHECK_FOR(v) ([UIDevice.currentDevice.systemVersion compare:@__JJRSMOVINGON_STR(v) options:NSNumericSearch] != NSOrderedAscending)
#define __JJRSMOVINGON_WARN_FOR(v) (YES _Pragma(__JJRSMOVINGON_STR(GCC warning(__JJRSMOVINGON_STR(Redundant iOS v check)))))
#pragma mark The macros
#ifdef __IPHONE_2_0
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_2_0
#define ENSURE_IPHONE_2_0 __JJRSMOVINGON_CHECK_FOR(2.0)
#else
#define ENSURE_IPHONE_2_0 __JJRSMOVINGON_WARN_FOR(2.0)
#endif
#endif
#ifdef __IPHONE_2_1
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_2_1
#define ENSURE_IPHONE_2_1 __JJRSMOVINGON_CHECK_FOR(2.1)
#else
#define ENSURE_IPHONE_2_1 __JJRSMOVINGON_WARN_FOR(2.1)
#endif
#endif
#ifdef __IPHONE_2_2
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_2_2
#define ENSURE_IPHONE_2_2 __JJRSMOVINGON_CHECK_FOR(2.2)
#else
#define ENSURE_IPHONE_2_2 __JJRSMOVINGON_WARN_FOR(2.2)
#endif
#endif
#ifdef __IPHONE_3_0
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_3_0
#define ENSURE_IPHONE_3_0 __JJRSMOVINGON_CHECK_FOR(3.0)
#else
#define ENSURE_IPHONE_3_0 __JJRSMOVINGON_WARN_FOR(3.0)
#endif
#endif
#ifdef __IPHONE_3_1
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_3_1
#define ENSURE_IPHONE_3_1 __JJRSMOVINGON_CHECK_FOR(3.1)
#else
#define ENSURE_IPHONE_3_1 __JJRSMOVINGON_WARN_FOR(3.1)
#endif
#endif
#ifdef __IPHONE_3_2
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_3_2
#define ENSURE_IPHONE_3_2 __JJRSMOVINGON_CHECK_FOR(3.2)
#else
#define ENSURE_IPHONE_3_2 __JJRSMOVINGON_WARN_FOR(3.2)
#endif
#endif
#ifdef __IPHONE_4_0
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_4_0
#define ENSURE_IPHONE_4_0 __JJRSMOVINGON_CHECK_FOR(4.0)
#else
#define ENSURE_IPHONE_4_0 __JJRSMOVINGON_WARN_FOR(4.0)
#endif
#endif
#ifdef __IPHONE_4_1
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_4_1
#define ENSURE_IPHONE_4_1 __JJRSMOVINGON_CHECK_FOR(4.1)
#else
#define ENSURE_IPHONE_4_1 __JJRSMOVINGON_WARN_FOR(4.1)
#endif
#endif
#ifdef __IPHONE_4_2
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_4_2
#define ENSURE_IPHONE_4_2 __JJRSMOVINGON_CHECK_FOR(4.2)
#else
#define ENSURE_IPHONE_4_2 __JJRSMOVINGON_WARN_FOR(4.2)
#endif
#endif
#ifdef __IPHONE_4_3
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_4_3
#define ENSURE_IPHONE_4_3 __JJRSMOVINGON_CHECK_FOR(4.3)
#else
#define ENSURE_IPHONE_4_3 __JJRSMOVINGON_WARN_FOR(4.3)
#endif
#endif
#ifdef __IPHONE_5_0
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_5_0
#define ENSURE_IPHONE_5_0 __JJRSMOVINGON_CHECK_FOR(5.0)
#else
#define ENSURE_IPHONE_5_0 __JJRSMOVINGON_WARN_FOR(5.0)
#endif
#endif
#ifdef __IPHONE_5_1
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_5_1
#define ENSURE_IPHONE_5_1 __JJRSMOVINGON_CHECK_FOR(5.1)
#else
#define ENSURE_IPHONE_5_1 __JJRSMOVINGON_WARN_FOR(5.1)
#endif
#endif
#ifdef __IPHONE_6_0
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_6_0
#define ENSURE_IPHONE_6_0 __JJRSMOVINGON_CHECK_FOR(6.0)
#else
#define ENSURE_IPHONE_6_0 __JJRSMOVINGON_WARN_FOR(6.0)
#endif
#endif
#ifdef __IPHONE_6_1
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_6_1
#define ENSURE_IPHONE_6_1 __JJRSMOVINGON_CHECK_FOR(6.1)
#else
#define ENSURE_IPHONE_6_1 __JJRSMOVINGON_WARN_FOR(6.1)
#endif
#endif
#ifdef __IPHONE_7_0
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0
#define ENSURE_IPHONE_7_0 __JJRSMOVINGON_CHECK_FOR(7.0)
#else
#define ENSURE_IPHONE_7_0 __JJRSMOVINGON_WARN_FOR(7.0)
#endif
#endif
#ifdef __IPHONE_7_1
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_1
#define ENSURE_IPHONE_7_1 __JJRSMOVINGON_CHECK_FOR(7.1)
#else
#define ENSURE_IPHONE_7_1 __JJRSMOVINGON_WARN_FOR(7.1)
#endif
#endif
#ifdef __IPHONE_8_0
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_8_0
#define ENSURE_IPHONE_8_0 __JJRSMOVINGON_CHECK_FOR(8.0)
#else
#define ENSURE_IPHONE_8_0 __JJRSMOVINGON_WARN_FOR(8.0)
#endif
#endif
#ifdef __IPHONE_8_1
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_8_1
#define ENSURE_IPHONE_8_1 __JJRSMOVINGON_CHECK_FOR(8.1)
#else
#define ENSURE_IPHONE_8_1 __JJRSMOVINGON_WARN_FOR(8.1)
#endif
#endif
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment