Package pycocoa :: Module runtime
[frames] | no frames]

Module runtime


Version: 18.03.11

Classes
  ObjCBoundMethod
Python wrapper for an Objective-C method (an IMP) which has been bound to some Id which is passed as the first method argument.
  ObjCClass
Python wrapper for an Objective-C class.
  ObjCInstance
Python wrapper for an Objective-C instance.
  ObjCMethod
This represents an unbound Objective-C method (really an IMP).
  ObjCSubclass
Use this to create a subclass of an existing Objective-C class.
Functions
 
split_encoding(encoding)
Split a type encoding into separate type encodings.
 
split_emcoding2(encoding, start=0)
Split the type encoding of a method signature into separate, single encodings and the combined encoding.
 
add_ivar(cls, name, ctype)
Add an instance variable to an Objective-C class, see also DeallocObserver below.
 
add_method(cls, selName, method, signature)
Add a method to an Objective-C class.
 
add_subclass(supercls, name, register=False, **ivars)
Create a new sub-class of the given super-class.
 
get_cfunctype(signature, codes=None)
Get the ctypes function type for a given signature type encoding.
 
get_class(name)
Get a registered Objective-C class by name.
 
get_classes(*prefixes)
Yield all loaded Objective-C classes with a name starting with one of the given prefixes.
 
get_classname(cls)
Get the name of an Objective-C class.
 
get_classof(obj)
Get the Objective-C class of an object.
 
get_ivar(obj, name, ctype=None)
Get the value of an instance variable.
 
get_ivars(cls, *prefixes)
Yield all instance variables of an Objective-C class with a name starting with one of the given prefixes.
 
get_inheritance(cls)
Yield the inheritance of an Objective-C class in bottom-up order.
 
get_metaclass(name)
Get a registered Objective-C metaclass by name.
 
get_method(cls, name)
Get a method of an Objective-C class by name.
 
get_methods(cls, *prefixes)
Yield all methods of an Objective-C class with a name starting with one of the given prefixes.
 
get_properties(cls_or_proto, *prefixes)
Yield all properties of an Objective-C class or protocol with a name starting with one of the given prefixes.
 
get_protocol(name)
Get a registered Objective-C protocol by name.
 
get_protocols(cls, *prefixes)
Yield all protocols of an Objective-C class with a name starting with one of the given prefixes.
 
get_selector(name)
Get an Objective-C selector (cmd) by name.
 
get_superclassof(obj)
Get the Objective-C superclass of an object.
 
isClass(obj)
Return True if the Objective-C object is a class.
 
isInstanceOf(obj, *Classes, **c_types)
Return True if the Objective-C object is an instance of any of the given Objective-C classes.
 
isMetaClass(obj)
Return True if the Objective-C object is a metaclass.
 
register_subclass(subcls)
Register an Objective-C subclass, see also DeallocObserver below.
 
send_message(receiver, selName, *args, **resargtypes)
Send message to the given receiver.
 
send_super(receiver, selName, *args, **resargtypes)
Send message to the superclass of the given receiver.
 
set_ivar(obj, name, value, ctype=None)
Set an instance variable of an Objective-C object to the given value.
Variables
  libobjc = <CDLL '/usr/lib/libobjc.dylib', handle 108278680 at ...
  OBJC_ASSOCIATION_COPY = 771
  OBJC_ASSOCIATION_COPY_NONATOMIC = 3
  OBJC_ASSOCIATION_RETAIN = 769
  OBJC_ASSOCIATION_RETAIN_NONATOMIC = 1
Function Details

split_encoding(encoding)

 

Split a type encoding into separate type encodings.

Does not handle bitfields, arrays, structs, unions, etc. and strips any offset, size or width specifiers from the encoding.

Examples:

>>> split_encoding('^v16@0:8')
>>> ['^v', '@', ':']
>>> split_encoding('{CGSize=dd}40@0:8{PyObject=@}Q32')
>>> ['{CGSize=dd}', '@', ':', '{PyObject=@}', 'Q']

Supported Type Encodings:

  • B = bool (C++ bool, C99 _Bool)
  • c, C = char, unsigned char
  • f, d = float, double
  • i, I = int, unsigned int
  • l, L = long, unsigned long (32-bit)
  • q, Q = long long, unsigned long long
  • s, S = short, unsigned short
  • t, T = 128-bit int, unsigned int
  • v = void
  • * = string (char *)
  • : = method selector (SEL/cmd)
  • # = class
  • #"name" = class "name"
  • @ = object (instance, statically typed, typed id, etc.)
  • @"name" = instance of class "name"
  • ^type = pointer to type
  • ? = unknown type (among other things, used for function pointers)

Unsupported Type Encodings:

  • bW = bit field of width W
  • [Ltype] = array of L items of type
  • {name=type...} = structure
  • (name=type...) = union
  • <...> = block

For Objective-C internal use only:

  • n, N = in, inout
  • o, O = out, bycopy
  • r, R = const, byref
  • V = oneway

Type encodings may be preceeded by a "name", for example a bit field "name"b1, structure fields {CGsize="width"d"heigth"d}, union items, etc. and all such "name" prefixes are ignored. See also Type Encodings, NSHipster Type Encodings and Digits in type encoding.

split_emcoding2(encoding, start=0)

 

Split the type encoding of a method signature into separate, single encodings and the combined encoding.

If necessary, the encoding is extended with the type encoding for the hidden method arguments id/self and SEL/cmd.

Does not handle bitfields, arrays, structs, unions, etc. and strips any offset, size or width specifiers from the encoding.

In the returned 2-tuple (codes, encoding), codes is the list of individual type encodings from item start=0 and encoding the combined type encoding in bytes and both extended if needed.

Example:

>>> split_emcoding2('v*')
>>> (['v', '@', ':', '*'], 'v@:*')

add_ivar(cls, name, ctype)

 

Add an instance variable to an Objective-C class, see also DeallocObserver below.

The ctype must be a ctypes type or a valid Objective-C type encoding as bytes.

add_method(cls, selName, method, signature)

 

Add a method to an Objective-C class.

The signature is the type encoding for the result and arguments of the method callable.

add_subclass(supercls, name, register=False, **ivars)

 

Create a new sub-class of the given super-class.

After calling add_subclass, you must register the new class with register_subclass and before using the new class.

New methods can be added after the class has been registered, but any ivars must be added before the class is registrated.

Or, use keyword argument register=True to register the class and specify any number of instance variables to be added as keyword arguments ivarname=ctype.

get_cfunctype(signature, codes=None)

 

Get the ctypes function type for a given signature type encoding.

Limited to basic type encodings and pointers to basic type encodings and does not handle arrays, bitfiels, arbitrary structs and unions.

The signature is a bytes object and not unicode and codes is a list of the individual type encodings. If codes is not supplied, it will be created by split_encoding the signature (not split_emcoding2).

get_classes(*prefixes)

 

Yield all loaded Objective-C classes with a name starting with one of the given prefixes.

For each class yield a 2-tuple (name, class) where name is the class name and class is the Objective-C class object.

get_ivars(cls, *prefixes)

 

Yield all instance variables of an Objective-C class with a name starting with one of the given prefixes.

For each ivar yield a 4-tuple (name, encoding, ctype, ivar) where name is the ivar name, encoding is the ivar's type encoding, ctype is the ivar's ctypes type and ivar the Ivar object.

get_methods(cls, *prefixes)

 

Yield all methods of an Objective-C class with a name starting with one of the given prefixes.

For each method yield a 4-tuple (name, encoding, rargtypes, method), where name is the method name, encoding is the type encoding of the method signature including the return type, rargtypes the ctypes signature, the argtypes list** preceeded by the restype and method the Method object.

**) In Python 3+ rargtypes is a map object, not a list.

get_properties(cls_or_proto, *prefixes)

 

Yield all properties of an Objective-C class or protocol with a name starting with one of the given prefixes.

For each property, yield a 3-tuple (name, attributes, setter, property) where attributes is a comma-separated list of the property attibutes, setter is the name of the property setter method, provided the property is writable and property is the Property object. The setter is an empty name '' for read-only properties.

Objective-C Property Attributes:

  • T<type>"name" = Type
  • & = Retain last value (retain)
  • C = Copy
  • D = Dynamic (@dynamic)
  • G<name> = Getter selector name
  • N = Non-atomic (nonatomic)
  • P = To be garbage collected
  • R = Read-only (readonly)
  • S<name> = Setter selector name
  • t<encoding> = Old-dtyle type encoding
  • W = Weak reference (__weak)

See Property Attributes.

get_protocols(cls, *prefixes)

 

Yield all protocols of an Objective-C class with a name starting with one of the given prefixes.

For each protocol, yield a 2-tuple (name, protocol) where name is the protocol name and protocol the Protocol object.

send_message(receiver, selName, *args, **resargtypes)

 

Send message to the given receiver.

By default, the result and all arguments are c_void_p wrapped.

Use keyword arguments restype=c_void_p and argtypes=[] to change the defaults. The restype defines the ctypes type for the returned result and argtypes is the list of ctypes types for the message arguments only (without the id/self and self/cmd arguments).

send_super(receiver, selName, *args, **resargtypes)

 

Send message to the superclass of the given receiver.

By default, the result and all arguments are c_void_p wrapped.

Use keyword arguments restype=c_void_p and argtypes=[] to change the defaults. The restype defines the ctypes type for the returned result and argtypes is the list of ctypes types for the message arguments only (without the id/self and self/cmd arguments).


Variables Details

libobjc

Value:
<CDLL '/usr/lib/libobjc.dylib', handle 108278680 at 1026d2150>