NullSafe is a simple category on NSNull that returns nil for unrecognised messages instead of throwing an exception. This eliminates a common cause of crashes, where (for example) JSON data contains a null value instead of an array or string, and the network code in the app isn't expecting it.
Supported iOS & SDK Versions
- Supported build target - iOS 11.0 / Mac OS 10.12 (Xcode 9.0)
- Earliest supported deployment target - iOS 9.0 / Mac OS 10.10
- Earliest compatible deployment target - iOS 4.3 / Mac OS 10.6
NOTE: 'Supported' means that the library has been tested with this version. 'Compatible' means that the library should work on this iOS version (i.e. it doesn't rely on any unavailable SDK features) but is no longer being tested for compatibility and may require tweaking or bug fixes to run correctly.
NullSafe works in both ARC and non ARC targets without modification.
Installation & Usage
To use NullSafe, just drag the NullSafe.m file into your project. NullSafe will be automatically loaded at runtime, you don't need to include any header files in your code.
Selectively Disabling NullSafe
NullSafe is enabled automatically as soon as the class files are added to a project target, however if you wish to disable NullSafe for a particular scheme (e.g. when running in debug mode) then you can disable it by adding the following pre-compiler macro to your build settings:
Or if you prefer, you could add something like this to your prefix.pch file:
#ifdef DEBUG #define NULLSAFE_ENABLED 0 #endif
- Updated for Xcode 9
- Fixed thread safety issue
- Added tvOS support to podspec
- Fixed nullability warning
- Fixed crash in iOS 8
- Removed NullSafe.h file (redundant)
- Now complies with -Weverything warning level
- Will now handle any known method, not just a subset
- Added NULLSAFE_ENABLED macro to easily enable/disable per scheme
- Added implementation cache for better performance
- Made it work by design rather than coincidence ;-)
- Initial release