Closed
Description
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 oficrate
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 likeNSString
,NSDictionary
, etc; this was however not the case. To get the actual feature you needFoundation_all
, that's highly unintuitive and totally undocumented. - The
NSMutableDictionary
wrapper inicrate
has a broken un-callable function namedinsert
, only theinsert_id
function is callable, that's also very unintuitive and undocumented as well, considering the example for that function usesinsert_id
instead ofinsert
. - Use of
AnyObject
andNSObject
. I found these wrappers mostly unintuitive as you can't do anything with them (i.e: no way to turn another object intoNSObject
as everything requires full specified type name), theinto
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()
aNSString
to turn it into aNSObject
or aAnyObject
. To do this one needs to callId::<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 andAnyObject
/NSObject
. I was nearly at giving up on this crate and returning to the good oldobjc
crate which I know is working and wouldn't have caused such a pain to crate and fill a simpleNSMutableDictionary
. - 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 theNSError
wrapper.