API Notes: Foundation framework

Introduction

An introduction to PyObjC describes the general method for translating Objective-C calls into Python calls, including the handling of pass-by-reference arguments and buffers.

This document describes where the PyObjC bindings for this framework are different from the general rule, such as mentioning APIs that are not supported or where the interface is different than expected.

API Notes

NSFastEnumeration

  • PyObjC doesn’t use or implement this protocol yet.

NSAppleEventDescriptor

  • -initWithAEDescNoCopy:, -aeDesc

    These methods are not supported.

NSArray

  • -getObjects:

    This method is not supported. Either use the NSArray like a normal python sequence or use -getObjects:inRange:.

NSException

  • raise:format:arguments:

    This method is not supported.

  • NSGetUncaughtExceptionHandler, NSSetUncaughtExceptionHandler

    These functions are not yet supported.

NSExpression

  • expressionWithFormat:

    This method is currently not supported because there is no API documentation, which makes it impossible to wrap this method with a vararg signature.

NSGarbageCollector

PyObjC doesn’t really support the GC yet. I’ve tried to code defensively, but have never tested a GC-enabled Python build and PyObjC relies on the usage of -dealloc in a number of cases.

  • -disableCollectorForPointer:, -enableCollectorForPointer:

    These methods are not yet supported.

NSHashTable

PyObjC only supports NSHashTable instances that have been configured to store objects (as opposed to arbitrary pointers).

NSIndexPath

  • -getIndexes:

    Use the indexPath as a python sequence instead.

  • NSIndexPath supports a number of convenience methods:

    path[idx] <==> path.indexAtPosition_(idx)
    len(path) <==> path.length()
    path + 4 <==> path.indexPathByAddingIndex_(4)
    

NSMapTable

PyObjC only supports NSMapTable instances that have been configured to store objects (as opposed to arbitrary pointers).

NSPointerArray

PyObjC only supports NSPointerArray instances that have been configured to store objects (as opposed to arbitrary pointers).

NSPointerFunctions

Accessing properties of this class is not supported.

NSMachPort

The delegate protocol of NSMachPort is not supported at the moment.

NSPredicate

  • -predicateWithFormat:arguments:

    This method is not supported.

NSProcessInfo

PyObjC defines a context named NSDisabledSuddenTermination. This can be used to disable sudden termination for a block of code. The context works on all versions of OSX, but only has a real side effect on OSX 10.6 or later.

Usage:

with NSDisabledSuddenTermination:
    # sudden termination is disabled here
    pass

PyObjC defines a context named NSDisabledAutomaticTermination. This can be used to disable automatic termination for a block of code. The context works on all versions of OSX, but only has a real side effect on OSX 10.6 or later.

Usage:

with NSDisabledAutomaticTermination("Updating status"):
    # sudden termination is disabled here
    pass

NSSet

  • +setWithObects:, -initWithObject:

    These methods are not supported, use other constructors instead.

NSOutputStream

  • -initToBuffer:capacity:, outputStreamToBuffer:capacity:

    This method is barely supported. The method only works when you pass a writable buffer argument as the buffer, and manually ensure that the buffer stays alive.

NSString

  • -getCharacters:

    This method is not supported.

NSValue

  • -getValue:

    This method is not supported

NSGetUncaughtExceptionHandler

This function is yet supported.