std/objc

Objective-C on macOS, through the C functions of its runtime, so it needs no Objective-C compiler; a module that uses it is marked #![unsafe]. On other systems the module is empty.

#![unsafe]
import "std/objc"

Handle text = ns_string("hola")
print(msg_int(text, "length"))                    // 4
c_func(Handle, Handle, Handle) Handle append = ptr_cast(msg_send())
Handle both = append(text, selector("stringByAppendingString:"), ns_string("!"))
print(from_ns_string(both))                       // hola!

A message is sent through objc_msgSend as a c_func of the method's signature, with the receiver and the selector first; msg_send() gives it.

Function Result
objc_class(name), selector(name), class_name(object) a class, a selector, and the name of an object's class
msg(o, name), msg_with(o, name, a), msg_with2(o, name, a, b) a message that gives an object
msg_int(o, name), msg_at(o, name, index) a message that gives an integer, and one that takes one
new_object(class) [[class alloc] init]
with_autorelease_pool(body) runs body in an autorelease pool
ns_string(text), from_ns_string(s) NSString
ns_array(items), from_ns_array(a) NSArray of objects
ns_dictionary(entries), from_ns_dictionary(d) NSDictionary with text keys
ns_data(data), from_ns_data(d) NSData
ns_url(address), ns_url(path, file: true), from_ns_url(u) NSURL
start_class(name, superclass), add_method(class, name, implementation, types), finish_class(class) a class written in Cuarzo, such as a delegate
set_object_data(class, object, handle), object_data(class, object) the data of Cuarzo each object of such a class holds
make_block(invoke, handle), block_data(block), free_block(block) a block whose code is a Cuarzo callback

A method's implementation and a block's code are C functions from c_callback: a method takes the object and the selector first, and its types are its Objective-C type encoding, as "v@:" or "q@:q"; a block's code takes the block first, whose data block_data gives.