Cross Platform

Nano supports the following platforms:

  • iOS 5.1+
  • Mac OS X 10.6+
  • Microsoft Windows XP, Vista, 7, and 8

Nano provides a single API on all supported platforms, and provides its own implementation if the underlying platform-specific API is lacking.

For example, NPreferences will automatically convert dictionaries to a simpler representation on platforms whose preference API does not support this type. This allows dictionaries to be stored in the native preference format without any conditional code.

Nanites

A set of additional classes are provided in the Nanites directory, which make it easy to integrate with platform-specific APIs.

These currently include:

  • AppKit
  • CoreFoundation
  • CoreGraphics
  • Qt
  • Skia
  • UIKit
  • Win32

Each Nanite typically includes helper functions to convert data types to and from their Nano equivalent, and may also simplify common tasks involving the native API.

Type Conversion

Most Nanites provide type conversion functions, to convert from API-specific types to their Nano equivalent (ToNN) or vice-versa (ToXX, where XX is an API-specific suffix):

#include "NCocoa.h" ... NArray srcArray, dstArray; NRange srcRange, dstRange; NSArray *nsArray; NSRange nsRange; // Convert from Nano to Cocoa nsArray = ToNS(srcArray); nsRange = ToNS(srcRange); // Convert from Cocoa to Nano dstArray = ToNN(nsArray); dstRange = ToNN(nsRange);

Returned pointers are disposed of automatically as auto-released objects, or as a pointer to state owned by the object being converted.

Comparison Operators

Several Nanites provide comparison operators, allowing types to be compared with != and == operators:

#include "NCoreGraphics.h" ... CGPoint point1, point2; CGSize size1, size2; CGRect rect1, rect2; if (point1 == point2) ; // Do something if points are equal if (size1 == size2) ; // Do something if sizes are equal if (rect1 != rect2) ; // Do something if rects are not equal

Safer Interfaces

Some APIs do not perform error checking, and require the caller test for NULL or a similar sentinel. This requires more code, and forgetting this test can lead to a crash:

#include "NCoreFoundation.h" ... CFStringRef cfString; // Retain the string // // CFSafeRetain will only call CFRetain if cfString is not NULL. CFSafeRetain(cfString); // Release the string // // CFSafeRelease will only call CFRelease if cfString is not NULL, // and then sets cfString to NULL to prevent further use. CFSafeRelease(cfString);

NWindows.h provides similar helpers for CloseHandle() and Release().

Simpler Interfaces

Some APIs are quite verbose, and can be simplified for their typical usage:

#include "NCocoa.h" ... NSString *nsString; NSImage *nsImage; // Equivalent to: // // = NSLocalizedString(@"WindowName", @""); // nsString = NSBundleString("WindowName"); // Equivalent to: // // = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] // pathForResource:@"Splash" // ofType:@"png"]] // nsImage = NSBundleImagePNG("Splash");