2017-01-30 8 views
0

連絡先コンテナ(CNContainer)に関連するグループ(CNGroup)のリストを取得する方法を探しています。 predicateを使用すると失敗します。CNContactStoreを使用してCNContainerからCNGroupの配列を取得する方法は?

私が使用しているコードは

func populateGroups(tableView:NSTableView,container:CNContainer){ 

    print("populateGroups.start") 

    print(container.name) 
    print(container.identifier) 

    let contactStore = CNContactStore() 

    do { 
     let groupsPredicate = CNGroup.predicateForGroups(withIdentifiers: [container.identifier]) 
     groups = try contactStore.groups(matching: groupsPredicate) 
     groupNames.removeAll(); 
     for group:CNGroup in groups { 
      self.groupNames.append(group.name) 
     } 
     tableView.reloadData() 
    } catch { 
     print("Unexpected error fetching groups") 
    } 

    print("populateGroups.finish") 

} 

私はそれからエラーが私には意味がありません取得しています。

行グループ= try contactStore.groups(matching:groupsPredicate)はエラーを引き起こします。

[アカウント]は、識別子47008233-A663-4A52-8487-9D7505847E29、エラーでアカウントの更新に失敗しました:私は更新していないよと混乱してエラードメイン= ABAddressBookErrorDomainコード= 1002 "(ヌル)"

任意のアカウント。

私はそのコード行をグループに変更すると、contactStore.groupsを試してみます(一致:なし) すべてのコンテナのすべてのグループを取得します。

CNContactContainerに属するすべてのCNGroupを返す述部を作成するにはどうすればよいですか。

答えて

0

私はすべてのグループから各グループは

func populateGroups(tableView:NSTableView,container:CNContainer){ 

    let contactStore = CNContactStore() 

    do { 
     let groups:[CNGroup] = try contactStore.groups(matching: nil) 
     self.groups.removeAll(); 
     groupNames.removeAll(); 
     for group:CNGroup in groups { 
      let groupContainerPredicate:NSPredicate = CNContainer.predicateForContainerOfGroup(withIdentifier: group.identifier) 
      let groupContainer:[CNContainer] = try contactStore.containers(matching: groupContainerPredicate) 
      if(groupContainer[0].identifier == container.identifier) { 
       self.groupNames.append(group.name) 
       self.groups.append(group) 
      } 
     } 
     tableView.reloadData() 

    } catch { 
     print("Unexpected error fetching groups") 
    } 

} 
CNContainer.predicateForContainerOfGroup

を使用して、問題のコンテナに属していることを確認することでこの問題を回避働いていました
関連する問題