我正在尝试在我的联系人列表之间搜索,我所能找到的只是查找姓名和姓氏,而不是查找号码电话。这是我的代码:
@echo off
:default_grid
set "0=-"
set "1=-"
set "2=-"
set "3=-"
set "4=-"
set "10=-"
set "11=-"
set "12=-"
set "13=-"
set "14=-"
set "20=-"
set "21=-"
set "22=-"
set "23=-"
set "24=-"
set "30=-"
set "31=-"
set "32=-"
set "33=-"
set "34=-"
set "40=-"
set "41=-"
set "42=-"
set "43=-"
set "44=-"
set pos=22
if %pos% EQU 22 set "22=O"
:grid
echo.
echo "%0%" "%10%" "%20%" "%30%" "%40%"
echo "%1%" "%11%" "%21%" "%31%" "%41%"
echo "%2%" "%12%" "%22%" "%32%" "%42%"
echo "%3%" "%13%" "%23%" "%33%" "%43%"
echo "%4%" "%14%" "%24%" "%34%" "%44%"
echo.
pause >nul
并给我错误:
“ [CNLabeledValue]”类型的值没有成员“范围”
我该如何解决?
答案 0 :(得分:0)
phoneNumbers
的{{1}}属性不是CNContact
。它是String
个对象的数组。
您需要扫描阵列,从每个CNLabeledValue
中提取CNPhoneNumber
。然后获取电话号码的CNLabeledValue
。最后,在该字符串值上使用stringValue
。
更改:
range(of:)
收件人:
$0.phoneNumbers.range(of: searchBar.text!, options: [.caseInsensitive, .diacriticInsensitive ]) != nil
请注意,第一个$0.phoneNumbers.contains { $0.value.stringValue.range(of: searchBar.text!, options: [.caseInsensitive, .diacriticInsensitive ]) != nil }
是$0
数组中的CNContact
。第二个contactList
是联系人$0
数组中的CNLabeldValue
。