I have an application written in Swift that pulls user contacts from their address book.
I want to filter out the contact that contains only the name of the company (so that you get the "alleged" contact with a real person, not a business).
Here's how it does in the version of my Objective-C application:
NSArray *allContacts = (__bridge_transfer NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook); NSPredicate *predicate = [NSPredicate predicateWithBlock:^BOOL(id person, NSDictionary *bindings) { NSString *firstName = CFBridgingRelease(ABRecordCopyValue((__bridge ABRecordRef)person, kABPersonFirstNameProperty)); NSString *lastName = CFBridgingRelease(ABRecordCopyValue((__bridge ABRecordRef)person, kABPersonLastNameProperty)); return (firstName || lastName); }]; NSArray *peopleNotCompanies = [allContacts filteredArrayUsingPredicate:predicate];
This works fine, so here is my attempt to do this in Swift:
var contactList: NSArray = ABAddressBookCopyArrayOfAllPeople(addressBook).takeRetainedValue() var predicate: NSPredicate = NSPredicate { (AnyObject person, NSDictionary bindings) -> Bool in var firstName: String = ABRecordCopyValue(person as ABRecordRef, kABPersonFirstNameProperty).takeRetainedValue() as String var lastName: String = ABRecordCopyValue(person as ABRecordRef, kABPersonLastNameProperty).takeRetainedValue() as String return firstName || lastName })
Now this has a couple of problems. I get these errors in the return statement and at the end of the predicate call:

How can I provide similar functionality found in my ObjC code in Swift? Or is there a better way to quickly check if a contact has ONLY the company name and then omit it from the final array?
Thanks!
source share