【发布时间】:2013-02-05 16:05:17
【问题描述】:
我正在开发获取具有相同电话号码的重复联系人的应用程序。 我的问题是常规的 foreach 与大量的联系很慢,我也知道使用谓词可以做到这一点。但我找不到任何带有 monotouch 的示例。
【问题讨论】:
标签: iphone ios xamarin.ios abaddressbook
我正在开发获取具有相同电话号码的重复联系人的应用程序。 我的问题是常规的 foreach 与大量的联系很慢,我也知道使用谓词可以做到这一点。但我找不到任何带有 monotouch 的示例。
【问题讨论】:
标签: iphone ios xamarin.ios abaddressbook
我不知道 ABAddressBook,但是如果您使用 Xamarin Mobile APi,那么您可以使用如下所示的谓词:
var abook = new AddressBook();
abook.RequestPermissions().ContinueWith (t =>
{
if (!t.Result)
return; // Permission denied
var builder = new StringBuilder();
// Full LINQ support
foreach (Contact c in abook.Where (c => c.FirstName == "Eric" && c.Phones.Any()))
{
builder.AppendLine (c.DisplayName);
foreach (Phone p in c.Phones)
builder.AppendLine (String.Format ("{0}: {1}", p.Label, p.Number));
builder.AppendLine();
}
contacts.Text = builder.ToString(); // Update UI
}, TaskScheduler.FromCurrentSynchronizationContext()); // Ensure we're on the UI Thread
来自http://betaapi.xamarin.com/?link=T%3aXamarin.Contacts.AddressBook
【讨论】:
您可以在 O(N) 时间内完成。此答案使用一个循环来识别数组中的重复项:https://stackoverflow.com/a/12948182/1441667。尝试将 Stuarts 的答案与这种方法结合起来。
【讨论】: