Check if the element is not empty iphone
Greetings ,

I am working on an iphone application which has to add entries to address book. the data is received from an array from a server . The thing is some of the field could be empty which result in the crash of application . i am looking for a method to add only the non empty elements .
i have mentioned the code i have used below


         for (int i = 0; i < [contact_id count]; i++) {
              ABAddressBookRef addressBook = ABAddressBookCreate();
              ABRecordRef record = ABPersonCreate();
		
              NSArray *contactFields= [[NSArray alloc]initWithObjects:@"first_name",@"name",@"email",@"mobile",@"website",nil];
		
              [requestExecute setMethod:@"execute" withObjects:[NSArray arrayWithObjects:database,
								   userid,
								   password,
								   @"res.partner.contact",
								   @"read",
								   [contact_id objectAtIndex:i],
								   contactFields,nil]];
		
		NSArray *contactData=[self executeXMLRPCRequest:requestExecute];
		NSLog(@"index is %@",contactData);
		NSEnumerator *enumerator = [contactData objectEnumerator];
		NSString *element;
		NSMutableArray *index = [[NSMutableArray alloc] init];
		while (element = [enumerator nextObject]) {
			
			[index addObject:element];
			
		}
		
		NSLog(@"index is %@",index);
		

		bool didAddPhone = [index objectAtIndex:2];
		NSLog(@"%@",didAddPhone);
		
		if(didAddPhone)
		{
			ABMultiValueRef phoneNumber = ABMultiValueCreateMutable(kABMultiStringPropertyType);
			ABMultiValueAddValueAndLabel(phoneNumber,(CFStringRef) [index objectAtIndex:2], kABPersonPhoneMobileLabel, NULL);
			ABRecordSetValue(record, kABPersonPhoneProperty, [index objectAtIndex:2], nil);
			NSLog(@"Address saved.....");
			
		}
		
		CFRelease(phoneNumber);
		
				
		ABMultiValueRef emailAddress = ABMultiValueCreateMutable(kABMultiStringPropertyType);
		
		bool didAddEmail = ABMultiValueAddValueAndLabel(emailAddress,(CFStringRef) [index objectAtIndex:4], kABWorkLabel, NULL);
		if (didAddEmail) 
		{
			ABRecordSetValue(record, kABPersonEmailProperty, [index objectAtIndex:4], nil);
			NSLog(@"Email saved.....");
					
		}
		CFRelease(emailAddress);
		
		ABMultiValueRef website = ABMultiValueCreateMutable(kABMultiStringPropertyType);
		bool didAddWebsite = ABMultiValueAddValueAndLabel(website,(CFStringRef) [index objectAtIndex:1], kABWorkLabel, NULL);
		
		if (didAddWebsite){
			
			ABRecordSetValue(record, kABPersonURLProperty, [index objectAtIndex:1], nil);
			NSLog(@"Website saved.....");
		}
			
		CFRelease(website);		
		
		ABRecordSetValue(record, kABPersonFirstNameProperty, [index objectAtIndex:3], nil); 
		ABRecordSetValue(record, kABPersonLastNameProperty, [index objectAtIndex:0], nil);
		
		NSLog(@"%@ and %@", [index objectAtIndex:3], [index objectAtIndex:0]);
	
		CFRelease(record);
		ABAddressBookAddRecord(addressBook, record, nil); 
		
		//save the record
		ABAddressBookSave(addressBook, nil);		
			
				
		CFRelease(addressBook);
	}


I appreciate any available help on this regard.

Thank you
Check if the element is not empty iphone
===

Greetings ,

I am working on an iphone application which has to add entries to address book. the data is received from an array from a server . The thing is some of the field could be empty which result in the crash of application . i am looking for a method to add only the non empty elements .
i have mentioned the code i have used below


         for (int i = 0; i < [contact_id count]; i++) {
              ABAddressBookRef addressBook = ABAddressBookCreate();
              ABRecordRef record = ABPersonCreate();
		
              NSArray *contactFields= [[NSArray alloc]initWithObjects:@"first_name",@"name",@"email",@"mobile",@"website",nil];
		
              [requestExecute setMethod:@"execute" withObjects:[NSArray arrayWithObjects:database,
								   userid,
								   password,
								   @"res.partner.contact",
								   @"read",
								   [contact_id objectAtIndex:i],
								   contactFields,nil]];
		
		NSArray *contactData=[self executeXMLRPCRequest:requestExecute];
		NSLog(@"index is %@",contactData);
		NSEnumerator *enumerator = [contactData objectEnumerator];
		NSString *element;
		NSMutableArray *index = [[NSMutableArray alloc] init];
		while (element = [enumerator nextObject]) {
			
			[index addObject:element];
			
		}
		
		NSLog(@"index is %@",index);
		

		bool didAddPhone = [index objectAtIndex:2];
		NSLog(@"%@",didAddPhone);
		
		if(didAddPhone)
		{
			ABMultiValueRef phoneNumber = ABMultiValueCreateMutable(kABMultiStringPropertyType);
			ABMultiValueAddValueAndLabel(phoneNumber,(CFStringRef) [index objectAtIndex:2], kABPersonPhoneMobileLabel, NULL);
			ABRecordSetValue(record, kABPersonPhoneProperty, [index objectAtIndex:2], nil);
			NSLog(@"Address saved.....");
			
		}
		
		CFRelease(phoneNumber);
		
				
		ABMultiValueRef emailAddress = ABMultiValueCreateMutable(kABMultiStringPropertyType);
		
		bool didAddEmail = ABMultiValueAddValueAndLabel(emailAddress,(CFStringRef) [index objectAtIndex:4], kABWorkLabel, NULL);
		if (didAddEmail) 
		{
			ABRecordSetValue(record, kABPersonEmailProperty, [index objectAtIndex:4], nil);
			NSLog(@"Email saved.....");
					
		}
		CFRelease(emailAddress);
		
		ABMultiValueRef website = ABMultiValueCreateMutable(kABMultiStringPropertyType);
		bool didAddWebsite = ABMultiValueAddValueAndLabel(website,(CFStringRef) [index objectAtIndex:1], kABWorkLabel, NULL);
		
		if (didAddWebsite){
			
			ABRecordSetValue(record, kABPersonURLProperty, [index objectAtIndex:1], nil);
			NSLog(@"Website saved.....");
		}
			
		CFRelease(website);		
		
		ABRecordSetValue(record, kABPersonFirstNameProperty, [index objectAtIndex:3], nil); 
		ABRecordSetValue(record, kABPersonLastNameProperty, [index objectAtIndex:0], nil);
		
		NSLog(@"%@ and %@", [index objectAtIndex:3], [index objectAtIndex:0]);
	
		CFRelease(record);
		ABAddressBookAddRecord(addressBook, record, nil); 
		
		//save the record
		ABAddressBookSave(addressBook, nil);		
			
				
		CFRelease(addressBook);
	}


I appreciate any available help on this regard.

Thank you