You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The issue is x is of type Id<AnyObject> rather than Id<Value> because I typed values as Id<NSArray>.
I can't type values as Id<NSArray<Value>> because Value doesn't implement the ClassType trait. I model many types as above and never have to deal with classes, and I hope to keep it that way.
The following fails for the same reason
I see you took away into_vec for lack of safety because the array is IsIdCloneable so may be cloned even when containing mutable elements.
When I try the into_vec code you used, that is
where T=Value here, this fails because to_vec converts to a vector of &AnyObject and then casting &AnyObject to *const T is an invalid cast.
So I'm really not sure at this point how to properly convert an array to a vector when the type of objects in the array don't implement ClassType.
The text was updated successfully, but these errors were encountered:
I assume you closed this because you figured out the problem by yourself, but for future reference, I'll give my two cents on this: What you're doing should be possible as just values.to_vec_retained(), and will (probably) eventually be fixed by #563.
But while it's not, the easiest fix is probably to use the code from to_vec_retained directly, with Value plugged in as the T:
let values:Id<NSArray<Value>> = msg_send_id![self, values];let v:Vec<Id<Value>> = values.to_vec().into_iter().map(|obj| unsafe{Id::retain(obj as*constValueas*mutValue).unwrap_unchecked()}).collect();
madsmtm
added
question
Further information is requested
A-objc2
Affects the `objc2`, `objc2-exception-helper` and/or `objc2-encode` crates
labels
Apr 3, 2024
When I model some Objective-C object type
Value
I'm confused on the best way to receive anNSArray
of these objects and convert toVec<Id<Value>>
.Here I model some fictional Objective-C type
Value
asThen calling method
values
withself
some instance of structValue
I receive anNSArray
of these valuesThe issue is
x
is of typeId<AnyObject>
rather thanId<Value>
because I typedvalues
asId<NSArray>
.I can't type
values
asId<NSArray<Value>>
becauseValue
doesn't implement theClassType
trait. I model many types as above and never have to deal with classes, and I hope to keep it that way.The following fails for the same reason
In
0.3.0-beta.5
the following worked fineI see you took away
into_vec
for lack of safety because the array isIsIdCloneable
so may be cloned even when containing mutable elements.When I try the
into_vec
code you used, that iswhere
T=Value
here, this fails becauseto_vec
converts to a vector of&AnyObject
and then casting&AnyObject
to*const T
is an invalid cast.So I'm really not sure at this point how to properly convert an array to a vector when the type of objects in the array don't implement
ClassType
.The text was updated successfully, but these errors were encountered: