提问人:daniel 提问时间:6/30/2023 更新时间:6/30/2023 访问量:15
如何将 KeyPath<CNContact、Array<CNLabeledValue>>转换为 KeyPath<CNContact, Any>
How to cast KeyPath<CNContact, Array<CNLabeledValue>> to KeyPath<CNContact, Any>
问:
我需要将 KeyPath 值放在 Array<KeyPath<CNContact,Any>> 类型的数组中。但是,\CNContact.phoneNumbers 无法强制转换为 KeyPath<CNContact,Any>。
这是我的测试代码:
let keyPath0: KeyPath<CNContact,Any> = \CNContact.phoneNumbers // Runtime error message: Key path value type '[CNLabeledValue<CNPhoneNumber>]' cannot be converted to contextual type 'Any'
let keyPath: KeyPath<CNContact,Any> = \CNContact.phoneNumbers as! KeyPath<CNContact,Any> // Warning message: Cast from 'KeyPath<CNContact, [CNLabeledValue<CNPhoneNumber>]>' to unrelated type 'KeyPath<CNContact, Any>' always fails
答: 暂无答案
评论
Value
KeyPath
Any
Any
Any
[CNLabeledValue<CNPhoneNumber>]
Any
[PartialKeyPath<CNContact>]