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
In the curent metadata standard there is a method fun resolveView(_ type:Type) : AnyStruct?
When you call that method you very often want to cast the resulting object as the type you sent in. So something like this?
let metadata=collection.borrowViewResolver(id: id).resolveView(Type<Voucher.Metadata>()) as! Voucher.Metadata
This gives no compile error as you have use as! but it will never succeed. The reason is that since resolveView returns an option you first have to unrwap it and then cast it. So this code will work
let metadata=collection.borrowViewResolver(id: id).resolveView(Type<Voucher.Metadata>())! as! Voucher.Metadata
Another issue I am pondering is why we need as! here. If i remove it i get mismatched types. expected Vouchre.Metadata?, got AnyStruct? but I have clearly ! the value before i cast it.
The text was updated successfully, but these errors were encountered:
In the curent metadata standard there is a method
fun resolveView(_ type:Type) : AnyStruct?
When you call that method you very often want to cast the resulting object as the type you sent in. So something like this?
This gives no compile error as you have use
as!
but it will never succeed. The reason is that since resolveView returns an option you first have to unrwap it and then cast it. So this code will workAnother issue I am pondering is why we need
as!
here. If i remove it i getmismatched types. expected Vouchre.Metadata?, got AnyStruct?
but I have clearly ! the value before i cast it.The text was updated successfully, but these errors were encountered: