Skip to content

Library is highly unintuitive and lacks support for objc interop #553

Description

@Yuri6037

I recently used 2 crates from this repository: icrate and objc2. Intitially I've seen the README in this repository which looked like I may have finally found a crate which will do the heavy-lifting of interacting with most Foundation types and provide Objective-C interoperability, however I've got a LOT of issues which makes me re-consider using the objc crate instead which was much lower-level and certainly has more unsafe. Nevertheless, I have found workarounds for now, I just wanted to leave a list of what I felt very unintuitive and undocumented and where I spent a considerable amount of time:

  • The Foundation feature of icrate isn't really a feature it's about 1% of one. Intuitively this looked like the Apple framework of the same name containing all base objects like NSString, NSDictionary, etc; this was however not the case. To get the actual feature you need Foundation_all, that's highly unintuitive and totally undocumented.
  • The NSMutableDictionary wrapper in icrate has a broken un-callable function named insert, only the insert_id function is callable, that's also very unintuitive and undocumented as well, considering the example for that function uses insert_id instead of insert.
  • Use of AnyObject and NSObject. I found these wrappers mostly unintuitive as you can't do anything with them (i.e: no way to turn another object into NSObject as everything requires full specified type name), the into and most other built-in trait function are not implemented or not easily usable and I couldn't find a direct way to easily .into() a NSString to turn it into a NSObject or a AnyObject. To do this one needs to call Id::<NSObject>::cast(mystring), the documentation for this behavior is nowhere to be found and I lost nearly 30 minutes figuring out how to do this by reading the very large code base as I was expecting to see a trait which would do the conversion between any wrapper struct and AnyObject/NSObject. I was nearly at giving up on this crate and returning to the good old objc crate which I know is working and wouldn't have caused such a pain to crate and fill a simple NSMutableDictionary.
  • It is impossible to turn an Id<NSError> into a *mut NSError, at least not easily, more on that later. That means you cannot easily call into other functions implemented in XCode/Objective-C. In order to do that I had to use a function I feel shouldn't be necessary: std::mem::transmute(Id::as_ptr(&obj)). Again I was looking for a .into_raw_ptr or .as_mut_ptr inside the NSError wrapper.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-frameworkAffects the framework crates and the translator for themdocumentationImprovements or additions to documentation

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions