title: How can i check the group's existence (whether group is available or not) in iphone ?
body: <p>I'm adding contacts in group of iphone by my application. Is there any other logic ??</p>
  
  <p>Can anybody tell me how can i check the groups existence ???</p>
  
  <p>I am using follwing code to check the group's existence but may be b'coz of loops my app s crash in iphone.</p>
  
  <p>//ab=AddressBook object</p>
  
  <pre><code>CFArrayRef a = ABAddressBookCopyArrayOfAllGroups(ab);
  
  for (CFIndex i = CFArrayGetCount(a)-1; i &gt;= 0; i--)
  
  {
  
      ABRecordRef     g = (ABRecordRef) CFArrayGetValueAtIndex(a, i);
  
  
  
      CFStringRef     s = (CFStringRef) ABRecordCopyValue(g, kABGroupNameProperty);
  
      CFComparisonResult  r = CFStringCompare((CFStringRef)name, s, 0);
  
      CFRelease(s);
  
  
  
      if (r == kCFCompareEqualTo)
  
      {
  
          group = CFRetain(g);
  
          break;
  
      }
  
  }
  
  CFRelease(a);
  
  
  
  CFErrorRef err = nil;
  
  if (!group)
  
  {
  
      group = ABGroupCreate();
  
      ABRecordSetValue(group, kABGroupNameProperty, name, &amp;err);
  
      if (!err)
  
      {
  
          ABAddressBookAddRecord(ab, group, &amp;err);
  
      }
  
      if (!err)
  
      {
  
          ABAddressBookSave(ab, &amp;err);
  
      }
  
  }
  
  if (err)
  
  {
  
      CFRelease(err);
  
  }
  </code></pre>