Fake Books are an indispensable tool for jazz musicians. They contain the melody, rhythm, and chord changes for hundreds of standards, allowing a player to jump into any session cold, and "fake it" through any tunes outside their repertoire. It's not sheet music, but rather the essence of tunes.

Cm11 B9 B♭m9 A♭13 G13 and trade fours with the tenor...

Programmers aren't all that different. Once you get the fundamentals down, it's really just about memorizing the APIs. Sure, you could read the docs, but nothing compares to the excitement of tinkering with code.

That's the idea behind The NSHipster Fake Book: expanding your repertoire through concise code samples, with minimal explanation. It's about letting concepts click as you discover new licks you'd never thought to try. Just pick it up and start playing—no matter what kind of chops you have.

In this book, you'll find over 200 code samples, ranging from the beginner and basic to the expert and obscure, across a variety of genres and use cases.





(And for those of you wondering, there are no plans for a print edition of The NSHipster Fake Book. Instead, in the tradition of the medium, feel free to print it out at home. Bonus points for Comb Binding)





Set List

Standards

Creating a Nonretained Object Value



Adding an Anonymous Observer to a Notification Center



Accessing Thread-Unsafe Objects from a Thread Dictionary



Converting a String to a Number



Converting a Number to a String



Implementing Indexed Subscripting



Implementing Keyed Subscripting



Using a Method that accepts an Error Parameter



Implementing a Method that takes an Error Parameter



Logging Class, Method, and Line Number Context



Key-Value Archiving & Unarchiving an Object



Archiving / Unarchiving an Object into NSUserDefaults



Creating a KeyPath from Selector



Adding an Item to the Keychain



Evaluating a Mathematical Expression



Decoding JSON



Encoding JSON



Getting the Name of the Device







Language & Runtime

Declaring an NS_ENUM Type



Declaring an NS_OPTIONS Type



Creating String Representations for Enumerated Type



Adding a Property to a Category



Swizzling a Method



Determining the Type of a Property



Determining the Type of a CFTypeRef



Specifying the Availability of a Method



Hiding a Class



Hiding a Method



Ignoring Compiler Warnings



Determining the Current System Memory Usage



Getting the Current OS Version



Declaring a Constant Value



Determining Whether an Object is Null



Declaring an Argument or Parameter as Unused



Creating Variadic Method



Creating a Variadic Function



Overloading Functions



Determining if ARC is Available



Conditionally Compiling for iOS & OS X Targets



Determining if Class is Available for Target Platform at Runtime



Determining if Method is Available for Target Platform at Runtime



Determining if Function is Available for Target Platform at Runtime



Adding a Class at Runtime



Adding a Method to a Class at Runtime



Getting the Subclasses and Superclasses of a Class



Requiring Method to call super



Determining the Caller of a Method



Creating Variadic Formatting Method



Intentionally Crashing the Current Process







Grand Central Dispatch

Dispatching Work Asynchronously to a Background Queue



Benchmarking the Execution Time of an operation



Monitoring Local File Changes



Creating a Singleton



Monitoring the Parent Process PID



Reading from STDIN



Monitoring Local File Changes



Dispatching a Timer



Cryptography



Encrypting & Decrypting Using AES-128 With PBKDF2 Key



Base64-Decoding Data



Base64-Encoding Data



Calculating MD5 Digest



Calculating SHA-1 Digest



Generating SHA-1 HMAC







Random

Creating a Random Integer



Creating a Random Double



Creating a Random String



Creating a Random Date



Generating Random Bytes



Creating a UUID



Creating a GUID







Collections

Enumerating an Array



Enumerating a Dictionary



Creating a Mutable Copy of an Array



Creating a Mutable Copy of a Dictionary



Creating a Case-Insensitive Dictionary



Accessing Mutable Dictionary in a Thread-Safe Manner



Reversing an Array



Shuffling an Array



Creating a String from an Array



Filtering Objects in Array by Class



Computing the Sum of an Array



Removing Duplicate Objects from an Array







Linguistics & Typography

Creating a Font from TTF / OTF Data



Determining the Current Language



Looking Up the Definition of a Word



Applying Foreground Color to an Attributed String



Creating an Attributed String from HTML



Getting Characters from a Character Set



Detecting Phone Number and Address from a String



Comparing Version Numbers



Finding Proper Nouns in a String



Calculating String Entropy



Formatting Strings



Determining the Language of a String



Concatenating String Literals



Determine if a String Contains Punctuation



Splitting a String into an Array



Determining if a String Contains a Particular Substring



Tokenizing a String



Squashing Whitespace in a String



Stripping Whitespace from a String



Getting the Small Caps Variant of a Font



Responding to Changes in a Text Field



Determining if a String is Empty



Determining if an Array is Empty



Determining if a Dictionary is Empty







Date & Time

Extracting Components from a Date



Creating a Date from Components



Performing Calendar Arithmetic



Parsing & Formatting an ISO 8601 timestamp



Parsing & Formatting an RFC 3339 Timestamp



Determining if Device is Set for 24 Hour Time







Filesystem

Finding Application Support Directory



Finding Caches Directory



Listing all files in a directory



Creating a Directory



Recursively Enumerating all files in a directory



Finding Documents Directory



Finding Downloads Directory



Determining the Creation Date of a File



Deleting a File



Determining if a File Exists



Finding Library Directory



Writing a String to Disk



Sorting Files by Filename



Setting Extended File Attributes







Cartography

Getting Directions Between Two Locations



Formatting a Localized Distance String



Searching for a Geographic Location



Creating Map Snapshots of Waypoints



Rendering Annotations on a Map View



Fitting a Map View to Annotations



Rendering Overlays on an MKMapView



Localizing Address Format of a Placemark



Describing a Placemark for a Coordinate Region



Creating a Custom Map Tile Overlay



Converting Degrees to Radians



Converting Radians to Degrees



Convert Radians to CLLocationDirection







Graphics

Animating a CAGradientLayer



Splitting a CGRect



Ensuring that a CGRect is not on a Pixel Boundary



Generating a QR Code



Reading a QR Code



Creating an Image for a Swatch of Color



Cropping an Image to Face



Detecting a Face in an Image



Resizing an Image



Converting an Image to Data



Determining the File Type of Image



Applying a CIFilter on an Image



Rounding Corners of a View



Getting Color RGB Components



Lightening / Darkening a Color



Creating a Color from Hexadecimal String



Inverting a Color







Networking

Making a Request with CFNetwork



Creating a Bound NSStream Pair



Constructing an HTTP User-Agent



Determining the MIME Type for a File Extension



Setting HTTP Headers for a URL Request



Escaping URLs



Building a URL relative to a Base URL



Setting the Shared URL Cache



Making Asynchronous Network Request with NSURLConnection



Making Synchronous Network Request with NSURLConnection



Making Asynchronous Network Request with NSURLSession



Getting List of Network Interfaces



Monitoring Network Reachability



Validating an SSL Certificate



Adding a URL to the Safari Reading List







UIKit