-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Library is highly unintuitive and lacks support for objc interop #553
Comments
Hey @Yuri6037, thanks a lot for the review, I hear your concerns and would like to resolve them.
I haven't written down that this is how it works, though I think it's somewhat documented though over on But agree that this can be confusing, though there is a reason it is done this way: enabling
It's not actually broken, but it only works for things that are "retainable", which works for e.g. That said, I agree that it is confusing, I'll fix that in the next (breaking) version of
This is being worked on, and my idea is indeed to add a helper trait, and to make
That's because it depends on how you want to transfer ownership:
In general, I agree that the introduction-level docs are basically non-existent, I tried to remedy that somewhat in #494, but my prose writing skills aren't that great, and I wasn't really happy with the example. I'll try to pick it up again when I get the time, and also to write some explanation notes, in particular on why |
Thanks a lot for your reply.
Indeed I think
Thanks, I look forward for the new version to be released. Could you also update the example on crates.io which currently uses the wrong function?
That would be fantastic and would indeed fix my problem. Also, if you get hit by the restrictions related to implementing foreign traits I'd also be fine with a custom
Usually what I want to do is just pass the object entirely to an Objective-C bridge which itself is used as a bridge to Swift and SwiftUI. So I mostly need |
It may not be obvious if you've cached everything, but try running In any case, I've opened #558 for tracking the renaming.
I assume you mean the example on docs.rs, if so, then yes, will do.
Hmm, I'm not sure that's true! Objective-C usually requires that you autorelease things that you pass back to it, otherwise you'll get a memory leak. Perhaps you could show me a sample of your code, then I can help you with what's required to avoid that?
Yeah, will release it probably somewhere around the end of January. |
I'm going to close this, since the actionable points are tracked elsewhere; reviewing your points again, we have currently:
Again, thank you for the review! |
I recently used 2 crates from this repository:
icrate
andobjc2
. 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 theobjc
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: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.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
.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
.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.The text was updated successfully, but these errors were encountered: