News for hackers. Stuff that matters.
Re:Building native macOS applications with Rust by Sidnicious on Wednesday November 30, 2016 @04:53PM (#13075057)
How do you subclass an ObjC class from Rust — say, to create a delegate for a UI element?

How is type safety handled? It looks like msg_send itself isn't type safe, but there are hand-written bindings… is that right?

Re:Building native macOS applications with Rust by kattrali on Wednesday November 30, 2016 @05:16PM (#13075223)
> How do you subclass an ObjC class from Rust — say, to create a delegate for a UI element?

The objc::declare module includes ClassDecl, which enables registering a new Objective-C class.

objc::declare documentation: http://sasheldon.com/rust-objc/objc/declare/index.html

Example usage: https://github.com/kattrali/rust-mac-app-examples/blob/maste...

> How is type safety handled? It looks like msg_send itself isn't type safe, but there are hand-written bindings… is that right?

Correct. msg_send operates on objc::runtime::Object references. The handwritten bindings use the impl_objc_class macro referenced in the post to define separate types for different Objective-C classes, and make messaging the wrong type of object a compile-time rather than a runtime error.

The impl_objc_class macro implements the ObjCClass and PartialEq traits for a new type: https://github.com/kattrali/rust-mac-app-examples/blob/maste...