Alterplay / APAddressBook

Easy access to iOS address book
MIT License
1.38k stars 192 forks source link

Filtering other fields besides phones (Swift) #80

Closed mplaczek closed 9 years ago

mplaczek commented 9 years ago

I'm trying to filter my contacts to remove those without an email address where the example below works as expected for phone entries:

    self.addressBook.filterBlock = {(contact: APContact!) -> Bool in
          return contact.phones.count > 0
        }

The following code returns "fatal error: unexpectedly found nil while unwrapping an Optional value"

    self.addressBook.filterBlock = {(contact: APContact!) -> Bool in
          return contact.emails.count > 0
        }

How should the emails filter be implemented to avoid this error? I assume the [AnyObject]! emails and phones arrays contain different types so they should be treated differently, however the solution is not readily apparent to my noob eyes!

belkevich commented 9 years ago

Looks like problem in Objective-C to Swift data type transfer. I hope it'll fixed with nullability support in next release. But I'm not sure. For now, you can add check for contact.phones != nil before call count property. Please, write here does it help or not

mplaczek commented 9 years ago

Ok... Once again I apologise. After you answered my previous FieldMask related question I realised it was having a knock on effect to the email filter. The code above does indeed work as expected if everything is set up correctly. Thank you very much for your time and support. It is greatly appreciated

belkevich commented 9 years ago

You are welcome!