objc2 icon indicating copy to clipboard operation
objc2 copied to clipboard

Add some examples/documentation for standard use cases (e..g, getting an ObjC struct into rust)

Open marcpabst opened this issue 1 year ago • 12 comments

I'm attempting to use objc2 for Apple iOS API interoperability, and I'm really struggling with basic tasks, such as retrieving an Objective-C struct (simd_float4x4, https://developer.apple.com/documentation/arkit/aranchor/2867981-transform?language=objc) from an object into Rust. Naively, I assumed this would work, but it doesn't:

#[repr(C)]
struct SimdFloat4x4 {
    columns: [SimdFloat4; 4],
}


#[repr(C)]
struct SimdFloat4 {
    x: f32,
    y: f32,
    z: f32,
    w: f32,
}

and then

let face_transform:  SimdFloat4x4 = unsafe { msg_send![anchor, transform] };

Could we have some more examples for things like this?

marcpabst avatar Feb 11 '24 14:02 marcpabst