PackageDescription: ObjectiveCConnect


Objective C Connect

Last published: June 18, 2021 by 'jsavidge'

Defines 3 Classes
Extends 19 Classes


This package provides a convenient and efficient ObjectiveC Connect framework.

Usage

"Looking up ObjectiveC classes."
Root.ObjectiveC.NSString

"Converting between String and NSString."
| string1 nsstring string2 |
string1 := 'testing'.
nsstring := Root.ObjectiveC.NSString stringWithCharacters: (string1 asByteArrayEncoding: #utf16) length: string1 size.
string2 := (nsstring cStringUsingEncoding: ObjectiveCRuntime NSUTF16LittleEndianStringEncoding) copyDoubleByteStringFromHeap: #utf16

"Converting between String and NSString the easy way."
| string1 nsstring string2 |
string1 := 'string1'.
nsstring := string1 asNSString.
string2 := String fromNSString: nsstring.

"Doing an affine rotation transform."
| matrix |
matrix := Root.ObjectiveC.NSAffineTransform transform.
matrix rotateByDegrees: 45.
matrix transformPoint: (1 @ 0) asNSPoint.

"Getting the current date"
Root.ObjectiveC.NSDate date printString

Implementation
The Root.ObjectiveC namespace gets transformed in to an instance of ObjectiveCNameSpace when started up on MacOSX. On other platforms, it remains (or transforms back to) a regular NameSpace instance. The ObjectiveCNameSpace handles class lookups. It caches class lookup results. When a new class is looked up, it will find the ObjectiveC class object and generate a Smalltalk ObjectiveCObject subclass to represent that ObjectiveC class. All of the methods on the ObjectiveC class are generated as methods on the Smalltalk class as DLLCC interfaces. Both the instance and class sides are generated. Arguments and return types get type cast, the list of type casting is described below.

The ObjectiveCCallback can be used to install code in to the ObjectiveC runtime environment on NSObject with a generate selector. This is useful when working with AppKit to hook up UI action callbacks. They typically have a "target" and an "action". The target is an object and the action is a selector (an instance of SEL). An ObjectiveCCallback generates a method on NSObject that can be called as the action and creates an instance of an NSObject that can be used as the target. You must keep a reference to the ObjectiveCCallback otherwise it will become garbage collected.

Argument type casts:
id CCompositePointer, ObjectiveCObject, SmallInteger, String __to_objc_id
Class CCompositePointer, ObjectiveCObject, Class __to_objc_Class
SEL CCompositePointer, Symbol, String __to_objc_SEL
BOOL Boolean __to_objc_BOOL
float Number __to_objc_float
double Number __to_objc_double
int Number __to_objc_int
_NSPoint CComposite<_NSPoint>, Point __to_objc_NSPoint
_NSRange CComposite<_NSRange>, Interval __to_objc_NSRange
_NSRect CComposite<_NSRect>, Rectangle __to_objc_NSRect
_NSSize CComposite<_NSSize>, Point __to_objc_NSSize

Return type casts:
id ObjectiveCObject __from_objc_id
Class Class __from_objc_Class
SEL Symbol __from_objc_SEL
BOOL SmallInteger __from_objc_BOOL
_NSPoint Point __from_objc_NSPoint
_NSRange Interval __from_objc_NSRange
_NSRect Rectangle __from_objc_NSRect
_NSSize Point __from_objc_NSSize

Limitations
ObjectiveC objects and classes do not survive across image save, you cannot resume using an ObjectiveCObject once an image has restarted.

Some ObjectiveC methods conflict with Smalltalk methods, such as the class side methods #initialize, #copy, #finalize, #release, #new, #hash, #superclass, #class and the instance side methods #hash and #class. Any method that has already been implemented in the ObjectiveCObject hierarchy (which subclasses from Object) will not be wrapped as a DLLCC call.