The Mockingbird Toolbox is a set of general-purpose utility code for use in iOS applications.
The Toolbox is the lowest-level module in the Mockingbird Library open-source project from Gilt Groupe.
Master branch status:
The Mockingbird Toolbox includes:
The MBBatteryMonitor
class reports the device’s power status and battery level, and also posts events through the NSNotificationCenter
when these values change.
The MBNetworkMonitor
class provides details about the current status of the device’s wifi and carrier network, and can also be configured to post NSNotificationCenter
events as network status changes occur.
Mockingbird Toolbox provides a simple but extensible caching architecture.
The MBThreadsafeCache
class implements a basic memory cache that can be safely shared across threads.
A subclass, MBFilesystemCache
, adds a filesystem backing store to the memory cache.
The MBConcurrentReadWriteCoordinator
class uses Grand Central Dispatch to provide an efficient mechanism for enforcing orderly read/write access to a shared resource.
MBThreadLocalStorage
provides an interface for safely sharing thread-local storage among unrelated units of code. The class can also be used as a lock-free cache: Objects that are expensive to create, such as NSDateFormatter
instances, can be cached in thread-local storage without incurring the locking overhead required by a shared object cache like MBThreadsafeCache
.
The Mockingbird Toolbox provides NSString
and NSMutableString
class extensions to help create, manipulate, and execute regular expressions.
These extensions make use of the MBRegexCache
for reusing regular expressions, which can be expensive to create.
The MBMessageDigest
class provides a high-level API for generating MD5 and SHA-1 secure one-way hashes from strings, NSData
instances, byte arrays, and files.
Class extensions for NSString
and NSData
are also provided to simplify creating message digests from existing objects.
The MBNetworkIndicator
class provides a mechanism to coordinate the display of the status bar network activity indicator.
Mockingbird Toolbox includes various utilities for creating, examining, and manipulating colors.
The Toolbox contains a UIImage
class extension that adds methods for scaling images, as well as a UIView
class extension for capturing the contents of a view as a UIImage
, CIImage
or CGImageRef
.
The MBBitmapPixelPlane
class represents a plane of pixels that can be accessed individually, regardless of the underlying pixel format. This allows direct extraction and manipulation of pixel data within a bitmap.
That’s just a quick summary.
For further details, start with the Mockingbird Toolbox API documentation.
Although you can directly add some or all of the source files in Mockingbird Toolbox to an existing project, we recommend using CocoaPods for integration.
CocoaPods will let you include only those portions of Mockingbird Toolbox that you actually wish to use, and it also gives you a simple way to keep up-to-date with any critical changes while providing versioning capabilities if you need to remain locked to a specific release or range of releases.
If you aren't already using CocoaPods, you'll find documentation on the CocoaPods website to help you get started.
Once you've got CocoaPods up and running, you can add all of the code in Mockingbird Toolbox to your project just by adding a line to your Podfile
:
pod 'MBToolbox'
The line above specifies that all the code in Mockingbird Toolbox should be added to your project. We've also provided a variety of subspecs in the MBToolbox.podspec
to give you fine-grained control over what ends up in your final binary. You can use just what you need, and you won't incur any overhead for unused features.
After you've added Mockingbird Toolbox to your Podfile
, you can then install the CocoaPod from the command line.
From within your project directory, issue the command:
pod install
Important: Take note of the output of the pod install
command. If you were not previously using an Xcode workspace for your project, CocoaPods will create one for you that includes your project and any installed CocoaPods. Going forward, you will need to use that workspace for development instead of your old project file.
Once you've run the pod install
command, you will be able to use the code you've included from within your project.
When you integrate Mockingbird Toolbox using CocoaPods, you should reference header files using the “library header” import notation, eg.:
#import <MBToolbox/MBDebug.h>
In the future, we may issue binary releases of Mockingbird Toolbox as iOS frameworks; using the notation above will allow you to seamlessly transition to using a framework.
If you are not using CocoaPods and are instead copying the Mockingbird Toolbox source into your project directly, you will need to reference those headers with “user header” notation:
#import "MBDebug.h"
If you only want to use some of what's available in the Toolbox, we've provided a number of CocoaPod subspecs that allow you to pick and choose exactly what you want to use from Mockingbird Toolbox.
Subspecs are added to your Podfile
as follows:
pod 'MBToolbox/BatteryMonitor'
pod 'MBToolbox/BitmapPixelPlane'
The lines above would add just the BatteryMonitor and BitmapPixelPlane portions of the Mockingbird Toolbox to your project.
Among the subspecs provided are:
- BatteryMonitor - includes the
MBBatteryMonitor
class and related items
- ThreadsafeCache - includes the
MBThreadsafeCache
class and related items - FilesystemCache - includes the
MBFilesystemCache
class and related items
- ConcurrentReadWriteCoordinator - specifies the
MBConcurrentReadWriteCoordinator
class - ThreadLocalStorage - specifies the
MBThreadLocalStorage
class
- FieldListFormatter - specifies the
MBFieldListFormatter
class - FormattedDescriptionObject - specifies the
MBFieldListFormatter
andMBFormattedDescriptionObject
classes
- BitmapPixelPlane - includes the
MBBitmapPixelPlane
class and related items - ColorTools - specifies the declarations within the
MBColorTools.h
file - RoundedRectTools - specifies the
MBRoundedRectTools
class - MBToolbox-UIColor - a
UIColor
class extension that adds several methods for getting information about and modifying colors - ImageScaling-UIImage - a
UIImage
class extension that adds methods for scaling images - SnapshotImage-UIView - a
UIView
class extension that adds methods for acquiring image snapshots of a view's contents
- MessageDigest - specifies the
MBMessageDigest
class - MessageDigest-NSString - includes the
MBMessageDigest
class and anNSString
class extension providing related convenience methods - MessageDigest-NSData - includes the
MBMessageDigest
class and anNSData
class extension providing related convenience methods - MessageDigest-Extensions - includes the
MBMessageDigest
class and all related class extensions
- NetworkIndicator - specifies the
MBNetworkIndicator
class - NetworkMonitor - specifies the
MBNetworkMonitor
service, a high-level replacement forReachability
that provides additional functionality
- OperationQueue - specifies the
MBOperationQueue
class - FilesystemOperations - includes the
MBOperationQueue
class and various filesystem operations
- RegexCache - specifies the
MBRegexCache
singleton - Regex-NSString - class extensions for
NSString
andNSMutableString
that provide convenience methods for handling regular expressions using theMBRegexCache
for improved performance
- ServiceManager - specifies the
MBServiceManager
singleton and theMBService
protocol
- Singleton - declares the
MBSingleton
andMBInstanceVendor
protocols, and the preprocessor macroMBImplementSingleton()
which provides a default singleton implementation based ondispatch_once()
- StringFunctions - declares the
MBForceString()
andMBTrimString()
inline functions, and theMBStringify()
preprocessor macro - StringConversions-NSData - an
NSData
class extension that adds methods for converting between hexadecimal strings andNSData
instances, and also provides methods for interpretingNSData
instances as byte data forNSString
s of various encodings - Indentation-NSString - an
NSString
class extension that adds methods for indenting the individual lines in a string using tabs and arbitrary prefixes - StringSizing-UIFont - a
UIFont
class extension that adds methods for performing common text measurement tasks
Additional subspecs are declared and documented in the podspec.
The Mockingbird Toolbox represents the foundation of the Mockingbird Library.
Over the years, Gilt Groupe has used and refined Mockingbird Library as the base platform for its various iOS projects.
Mockingbird began life as AppFramework, created by Jesse Boyes.
AppFramework found a home at Gilt Groupe and eventually became Mockingbird Library.
In recent years, Mockingbird Library has been developed and maintained by Evan Coyne Maloney, Gilt Groupe’s principal iOS engineer.
Mockingbird Library and Mockingbird Toolbox © Copyright 2009-2015, Gilt Groupe.
Licensed under the MIT license.