ObjCRuntime¶
-
public class
ObjCRuntime
extends NativeRuntime¶ ObjCRuntime.
NativeRuntime
implementation used for supporting Objective-C features like NSObjects and block codes.
Methods¶
addExternalPackage¶
addExternalPackagesForPrefix¶
associateObjCObject¶
associateObjCObject¶
-
public static void
associateObjCObject
(ObjCObject owner, Object instance)¶ Associates an object to an Objective-C object.
The Objective-C object will retain the object for itself and it will release the object when it gets deallocated.
Parameters: - owner – Object to associate with
- instance – Object to add
associateObjCObject¶
-
public static void
associateObjCObject
(long owner, Object instance, String name, java.lang.Class<?>[] argTypes)¶ Associates an object to an Objective-C object as an Objective-C Block.
The Objective-C object will retain the object for itself and it will release the object when it gets deallocated.
Parameters: - owner – Object to associate with
- instance – Object to add
- name – Block name
- argTypes – Block argument types
associateObjCObject¶
-
public static void
associateObjCObject
(ObjCObject owner, Object instance, String name, java.lang.Class<?>[] argTypes)¶ Associates an object to an Objective-C object as an Objective-C block.
The Objective-C object will retain the object for itself and it will release the object when it gets deallocated.
Parameters: - owner – Object to associate with
- instance – Object to add
- name – Block name
- argTypes – Block argument types
associateObjCObject¶
-
public static native void
associateObjCObject
(long object, long instance)¶ Associates an object to an Objective-C object.
The Objective-C object will retain the object for itself and it will release the object when it gets deallocated.
Also documented in ObjCRuntime.h
Parameters: - object – The ObjCObject to which we want to associate the instance
- instance – The object we want to associate
autoreleaseObject¶
-
public static native void
autoreleaseObject
(long pointer)¶ Autoreleases an Objective-C object.
Also documented in ObjCRuntime.h
Parameters: - pointer – The Objective-C object we want to autorelease
autoreleasepool¶
autoreleasepool¶
cast¶
-
public static <T extends ObjCObject> T
cast
(Object instance, java.lang.Class<T> cls)¶ Casts an instance to a given Objective-C type with native transparency.
Parameters: - <T> – Objective-C class to cast to
- instance – The instance we want to cast
- cls – The desired type of the class
Returns: The new object with the given type
cast¶
-
public static <T extends ObjCObject> T
cast
(Object instance, java.lang.Class<T> cls, boolean transparent)¶ Casts an instance to a given Objective-C type with a given native transparency.
Parameters: - <T> – Objective-C class to cast to
- instance – The instance we want to cast
- cls – The desired type of the class
- transparent – If this is true, then native side will see only the original peer
Returns: The new object with the given type
cast¶
-
public static <T extends ObjCObject> T
cast
(OpaquePtr ptr, java.lang.Class<T> cls)¶ Casts an opaque pointer to a given Objective-C type.
Parameters: - <T> – Objective-C class to cast to
- ptr – The opaque pointer we want to cast
- cls – The desired type of the class
Returns: The new object with the given type
cast¶
-
public static <T extends OpaquePtr> T
cast
(ObjCObject obj, java.lang.Class<T> cls)¶ Casts an Objective-C object to an opaque pointer.
Parameters: - <T> – opaque pointer type class to cast to
- obj – The Objective-C object we want to cast
- cls – The desired type of the class
Returns: The new opaque pointer with the given type
castToProtocol¶
-
public static <T> T
castToProtocol
(Object instance, java.lang.Class<T> cls)¶ Casts an instance to a given Objective-C protocol type with native transparency.
Parameters: - <T> – Objective-C class to cast to
- instance – The instance we want to cast
- cls – The desired type of the class
Returns: The new object with the given type
castToProtocol¶
-
public static <T> T
castToProtocol
(Object instance, java.lang.Class<T> cls, boolean transparent)¶ Casts an instance to a given Objective-C protocol with a given native transparency.
Parameters: - <T> – Objective-C class to cast to
- instance – The instance we want to cast
- cls – The desired type of the class
- transparent – If this is true, then native side will see only the original peer
Returns: The new object with the given type
copyBlock¶
-
public static native long
copyBlock
(long object)¶ Copies a native block.
Also documented in ObjCRuntime.h
Parameters: - object – The object we want to copy
Returns: The copied block
createAutoreleasePool¶
-
public static native long
createAutoreleasePool
()¶ Creates a new autorelease pool.
Also documented in ObjCRuntime.h
Returns: The newly created autorelease pool
createDataForJavaBlock¶
createDataForNativeBlock¶
createDataForNativeProtocolProxy¶
createJavaString¶
createNativeCallbackFromJavaInstance¶
-
public static native long
createNativeCallbackFromJavaInstance
(Object instance, long data)¶ Constructs an Objective-C block from a Java method.
Also documented in ObjCRuntime.h
Parameters: - instance – The Java instance we want to create native callback for
- data – The data pointer created by a call to createDataForJavaBlock()
Returns: The native callback
createNativeString¶
createProxyClass¶
createProxyClassWithExtension¶
-
public static native long
createProxyClassWithExtension
(java.lang.Class<?> type, String base, java.lang.Class<? extends ProxyExtensionBase> extension)¶ Constructs an Objective-C class from a Java class and adds implementations specified by extension.
Also documented in ObjCRuntime.h
Parameters: - type – The Java class we want to create proxy for
- base – Name of the base Objective-C class to be used as super class
- extension – The extension we want to use extra selectors from
Returns: The newly created Objective-C class
createProxyInstance¶
-
public static native long
createProxyInstance
(long type, Object instance)¶ Instantiates a proxy class for a Java instance. Works only for classes we generate with Java_org_natj_objc_ObjCRuntime_createProxyClass().
Also documented in ObjCRuntime.h
Parameters: - type – The Objective-C class object we want to instantiate
- instance – Java instance we want to create proxy object for
Returns: The Objective-C instance
createStrongPointer¶
-
public static Pointer
createStrongPointer
(long peer, boolean owned)¶ Creates a strong pointer to an Objective-C object.
Retains if doing so is needed to keep the strong ownership.
Parameters: - peer – The pointer
- owned – If this is false, the pointer objects will be retained
Returns: The created
Pointer
object
createWeakReference¶
-
public static WeakReference
createWeakReference
(long peer)¶ Creates a weak reference to an Objective-C object.
Parameters: - peer – The pointer
Returns: The created
Pointer
object
destroyWeak¶
-
public static native void
destroyWeak
(long location)¶ Destroys a weak reference to an Objective-C object.
Also documented in ObjCRuntime.h
Parameters: - location – The address of the reference
disposeObject¶
-
public static void
disposeObject
(Object object)¶ Tries to dispose the Objective-C peer of a given object
This will invalidate the given object and thus further use may result in undefined behaviour.
This will only work for objects originated from native side, namely: Bindings, Native Blocks and Protocol Proxies.
Parameters: - object – The object of which we want to dispose the native peer
dissociateObjCObject¶
-
public static void
dissociateObjCObject
(long owner, Object instance)¶ Removes an object from an Objective-C object’s association list.
If the object was associated with the Objective-C object then it will be removed from the association list and released.
Parameters: - owner – Object to dissociate from
- instance – Object to remove
dissociateObjCObject¶
-
public static void
dissociateObjCObject
(ObjCObject owner, Object instance)¶ Removes an object from an Objective-C object’s association list.
If the object was associated with the Objective-C object then it will be removed from the association list and released.
Parameters: - owner – Object to dissociate from
- instance – Object to remove
dissociateObjCObject¶
-
public static void
dissociateObjCObject
(long owner, Object instance, String name, java.lang.Class<?>[] argTypes)¶ Removes an Objective-C block object from an Objective-C object’s association list.
If the object was associated with the Objective-C object then it will be removed from the association list and released.
Parameters: - owner – Object to dissociate from
- instance – Object to remove
- name – Block name
- argTypes – Block argument types
dissociateObjCObject¶
-
public static void
dissociateObjCObject
(ObjCObject owner, Object instance, String name, java.lang.Class<?>[] argTypes)¶ Removes an Objective-C block object from an Objective-C object’s association list.
If the object was associated with the Objective-C object then it will be removed from the association list and released.
Parameters: - owner – Object to dissociate from
- instance – Object to remove
- name – Block name
- argTypes – Block argument types
dissociateObjCObject¶
-
public static native void
dissociateObjCObject
(long object, long instance)¶ Removes an object from an Objective-C object’s association list.
If the object was associated with the Objective-C object then it will be removed from the association list and released.
Also documented in ObjCRuntime.h
Parameters: - object – The ObjCObject with which we want to dissociate the instance
- instance – The object we want to dissociate
doRegistration¶
forwardBooleanBlockCall¶
-
public static native boolean
forwardBooleanBlockCall
(long peer, long data, Object[] args)¶ Forwards a call to a boolean native block.
Parameters: - peer – The block to call
- data – The native block data generated by a call to createDataForNativeBlock()
- args – The arguments of the call
Returns: The result of the call
forwardBooleanProtocolCall¶
-
public static native boolean
forwardBooleanProtocolCall
(long peer, long data, Object[] args)¶ Forwards a call to a boolean native protocol proxy.
Parameters: - peer – The native protocol peer
- data – The native protocol proxy data generated by a call to createDataForNativeProtocolProxy()
- args – The arguments of the call
Returns: The result of the call
forwardByteBlockCall¶
-
public static native byte
forwardByteBlockCall
(long peer, long data, Object[] args)¶ Forwards a call to a byte native block.
Parameters: - peer – The block to call
- data – The native block data generated by a call to createDataForNativeBlock()
- args – The arguments of the call
Returns: The result of the call
forwardByteProtocolCall¶
-
public static native byte
forwardByteProtocolCall
(long peer, long data, Object[] args)¶ Forwards a call to a byte native protocol proxy.
Parameters: - peer – The native protocol peer
- data – The native protocol proxy data generated by a call to createDataForNativeProtocolProxy()
- args – The arguments of the call
Returns: The result of the call
forwardCharBlockCall¶
-
public static native char
forwardCharBlockCall
(long peer, long data, Object[] args)¶ Forwards a call to a char native block.
Parameters: - peer – The block to call
- data – The native block data generated by a call to createDataForNativeBlock()
- args – The arguments of the call
Returns: The result of the call
forwardCharProtocolCall¶
-
public static native char
forwardCharProtocolCall
(long peer, long data, Object[] args)¶ Forwards a call to a char native protocol proxy.
Parameters: - peer – The native protocol peer
- data – The native protocol proxy data generated by a call to createDataForNativeProtocolProxy()
- args – The arguments of the call
Returns: The result of the call
forwardDoubleBlockCall¶
-
public static native double
forwardDoubleBlockCall
(long peer, long data, Object[] args)¶ Forwards a call to a double native block.
Parameters: - peer – The block to call
- data – The native block data generated by a call to createDataForNativeBlock()
- args – The arguments of the call
Returns: The result of the call
forwardDoubleProtocolCall¶
-
public static native double
forwardDoubleProtocolCall
(long peer, long data, Object[] args)¶ Forwards a call to a double native protocol proxy.
Parameters: - peer – The native protocol peer
- data – The native protocol proxy data generated by a call to createDataForNativeProtocolProxy()
- args – The arguments of the call
Returns: The result of the call
forwardFloatBlockCall¶
-
public static native float
forwardFloatBlockCall
(long peer, long data, Object[] args)¶ Forwards a call to a float native block.
Parameters: - peer – The block to call
- data – The native block data generated by a call to createDataForNativeBlock()
- args – The arguments of the call
Returns: The result of the call
forwardFloatProtocolCall¶
-
public static native float
forwardFloatProtocolCall
(long peer, long data, Object[] args)¶ Forwards a call to a float native protocol proxy.
Parameters: - peer – The native protocol peer
- data – The native protocol proxy data generated by a call to createDataForNativeProtocolProxy()
- args – The arguments of the call
Returns: The result of the call
forwardIntBlockCall¶
-
public static native int
forwardIntBlockCall
(long peer, long data, Object[] args)¶ Forwards a call to a int native block.
Parameters: - peer – The block to call
- data – The native block data generated by a call to createDataForNativeBlock()
- args – The arguments of the call
Returns: The result of the call
forwardIntProtocolCall¶
-
public static native int
forwardIntProtocolCall
(long peer, long data, Object[] args)¶ Forwards a call to a int native protocol proxy.
Parameters: - peer – The native protocol peer
- data – The native protocol proxy data generated by a call to createDataForNativeProtocolProxy()
- args – The arguments of the call
Returns: The result of the call
forwardLongBlockCall¶
-
public static native long
forwardLongBlockCall
(long peer, long data, Object[] args)¶ Forwards a call to a long native block.
Parameters: - peer – The block to call
- data – The native block data generated by a call to createDataForNativeBlock()
- args – The arguments of the call
Returns: The result of the call
forwardLongProtocolCall¶
-
public static native long
forwardLongProtocolCall
(long peer, long data, Object[] args)¶ Forwards a call to a long native protocol proxy.
Parameters: - peer – The native protocol peer
- data – The native protocol proxy data generated by a call to createDataForNativeProtocolProxy()
- args – The arguments of the call
Returns: The result of the call
forwardObjectBlockCall¶
-
public static native Object
forwardObjectBlockCall
(long peer, long data, Object[] args)¶ Forwards a call to a Object native block.
Parameters: - peer – The block to call
- data – The native block data generated by a call to createDataForNativeBlock()
- args – The arguments of the call
Returns: The result of the call
forwardObjectProtocolCall¶
-
public static native Object
forwardObjectProtocolCall
(long peer, long data, Object[] args)¶ Forwards a call to a Object native protocol proxy.
Parameters: - peer – The native protocol peer
- data – The native protocol proxy data generated by a call to createDataForNativeProtocolProxy()
- args – The arguments of the call
Returns: The result of the call
forwardShortBlockCall¶
-
public static native short
forwardShortBlockCall
(long peer, long data, Object[] args)¶ Forwards a call to a short native block.
Parameters: - peer – The block to call
- data – The native block data generated by a call to createDataForNativeBlock()
- args – The arguments of the call
Returns: The result of the call
forwardShortProtocolCall¶
-
public static native short
forwardShortProtocolCall
(long peer, long data, Object[] args)¶ Forwards a call to a short native protocol proxy.
Parameters: - peer – The native protocol peer
- data – The native protocol proxy data generated by a call to createDataForNativeProtocolProxy()
- args – The arguments of the call
Returns: The result of the call
forwardVoidBlockCall¶
forwardVoidProtocolCall¶
-
public static native void
forwardVoidProtocolCall
(long peer, long data, Object[] args)¶ Forwards a call to a void native protocol proxy.
Parameters: - peer – The native protocol peer
- data – The native protocol proxy data generated by a call to createDataForNativeProtocolProxy()
- args – The arguments of the call
getClassByName¶
getClassName¶
getClassParent¶
-
public static native long
getClassParent
(long object)¶ Returns the parent of an Objective-C class object.
Also documented in ObjCRuntime.h
Parameters: - object – The Objective-C class object we want to get the parent of
Returns: The parent class
getDefaultUnboxPolicy¶
-
public byte
getDefaultUnboxPolicy
()¶ Returns the default unbox policy for variadic arguments.
For Objective-C Runtime the policy is boxing, because this runtime does have object types.
Returns: The default unbox policy.
getExceptionStacktrace¶
-
public static String
getExceptionStacktrace
(Throwable throwable)¶ Print full description of throwable object into single string including name, reason, stacktrace and other info.
Used during converting java throwable to NSException with keeping stacktrace information.
Parameters: - throwable – input object
Returns: full stacktrace of throwable object
getHierarchyRootType¶
-
public static java.lang.Class<? extends ObjCObject>
getHierarchyRootType
()¶ Returns the resolved hierarchy root type.
Returns: Root type class
getInitTargetOnCurrentThread¶
getInstanceForJavaBlock¶
-
public static native Object
getInstanceForJavaBlock
(long callback)¶ Constructs a Java instance from a given callback. Works only with callbacks we create with createNativeCallbackFromJavaInstance().
Also documented in ObjCRuntime.h
Parameters: - callback – The callback we want to create Java instance from
Returns: The Java instance
getJavaReferenceOfBindingObject¶
getJavaReferenceOfCustomObject¶
getJavaTypeForHybridClass¶
getObjCCastProxyPeer¶
-
public static native long
getObjCCastProxyPeer
(long instance)¶ Returns the peer of a _NatJObjCCastProxy object.
Also documented in ObjCRuntime.h
Parameters: - instance – The instance of the proxy target
Returns: The peer of _NatJObjCCastProxy
getObjectClass¶
-
public static native long
getObjectClass
(long peer)¶ Returns the Objective-C class of an Objective-C object.
Also documented in ObjCRuntime.h
Parameters: - peer – The Objective-C object we want to get the class of
Returns: The class of the Objective-C object
getObjectClassName¶
getObjectDescription¶
handleFrameworkInitializer¶
-
public void
handleFrameworkInitializer
(IFrameworkInitializer initializer)¶ Handles an @{link org.moe.natj.objc.IFrameworkInitializer} instance.
Parameters: - initializer – Framework initializer
isKindOfHybridClass¶
-
public static native boolean
isKindOfHybridClass
(long peer)¶ Determines whether an Objective-C class is a hybrid class.
Also documented in ObjCRuntime.h
Parameters: - peer – The Objective-C class object
Returns: Whether the given class is a runtime created hybrid class
isKindOfInheritedClass¶
-
public static native boolean
isKindOfInheritedClass
(long peer)¶ Determines whether an Objective-C class is a runtime created inherited class.
Also documented in ObjCRuntime.h
Parameters: - peer – The Objective-C class object
Returns: Whether the given class is a runtime created inherited class
isKindOfProxyClass¶
-
public static native boolean
isKindOfProxyClass
(long peer)¶ Determines whether an Objective-C class is a runtime created proxy class.
Also documented in ObjCRuntime.h
Parameters: - peer – The Objective-C class object
Returns: Whether the given class is a runtime created proxy class
isObjectBlock¶
-
public static native boolean
isObjectBlock
(long object)¶ Determines whether the given object is a block.
Also documented in ObjCRuntime.h
Parameters: - object – The object we want to check
Returns: Whether the object is a block
isObjectString¶
-
public static native boolean
isObjectString
(long object)¶ Determines whether the given object is a string.
Also documented in ObjCRuntime.h
Parameters: - object – The object we want to check
Returns: Whether the object is a string
isStackBlock¶
-
public static native boolean
isStackBlock
(long object)¶ Determines whether the given object is a stack block.
Also documented in ObjCRuntime.h
Parameters: - object – The object we want to check
Returns: Whether the object is a stack block
loadWeak¶
-
public static native long
loadWeak
(long location)¶ Loads a weak reference to an Objective-C object.
Also documented in ObjCRuntime.h
Parameters: - location – The address of the reference
Returns: The referenced Objective-C object
lockObject¶
-
public static native void
lockObject
(long object)¶ Locks Objective-C object.
Also documented in ObjCRuntime.h
Parameters: - object – The Objective-C object we want to lock
registerSelector¶
releaseAutoreleasePool¶
-
public static native void
releaseAutoreleasePool
(long pool)¶ Releases an autorelease pool.
Also documented in ObjCRuntime.h
Parameters: - pool – The pool we want to release
releaseObject¶
-
public static native void
releaseObject
(long pointer)¶ Releases an Objective-C object.
Also documented in ObjCRuntime.h
Parameters: - pointer – The Objective-C object we want to release
resolveObjCClass¶
retainObject¶
-
public static native void
retainObject
(long pointer)¶ Retains an Objective-C object.
Also documented in ObjCRuntime.h
Parameters: - pointer – The Objective-C object we want to retain
setJavaReferenceOfBindingObject¶
-
public static native void
setJavaReferenceOfBindingObject
(long peer, Object ref)¶ Sets the Java instance associated with an Objective-C object.
Also documented in ObjCRuntime.h
Parameters: - peer – The Objective-C object we want to set the associated Java instance of
- ref – The Java instance we want to associate with the Objective-C object
setJavaReferenceOfCustomObject¶
-
public static native void
setJavaReferenceOfCustomObject
(long peer, Object ref)¶ Sets the custom Java instance associated with an Objective-C object.
Also documented in ObjCRuntime.h
Parameters: - peer – The Objective-C object we want to set the associated Java instance of
- ref – The Java instance we want to associate with the Objective-C object
storeWeak¶
-
public static native void
storeWeak
(long object, long location)¶ Stores a weak reference to an Objective-C object.
Also documented in ObjCRuntime.h
Parameters: - object – The Objective-C object we want to store weak reference for
- location – The address of the reference