2

I know it's not available since Xcode-beta 5. Please refer to this and this.

I have this source which is an extension for Array:

extension Array {
    func contains(object:AnyObject!) -> Bool {
        if(self.isEmpty) {
            return false
        }

        let array: NSArray = self.bridgeToObjectiveC();

       return array.containsObject(object)
    }
}

I modified it:

extension Array {
    func contains(object:AnyObject!) -> Bool {
        if(self.isEmpty) {
            return false
        }

        return (self as NSArray).containsObject(object);
    }

Unfortunately this doesn't work. The error message is:

Cannot convert the expression's type 'AnyObject!' to type 'NSArray'

What should I do? Thanks

Community
  • 1
  • 1
Bagusflyer
  • 12,675
  • 21
  • 96
  • 179

1 Answers1

1

Note that Swift has a 'find' function that you can use to see if an element is in an array or not:

find(array,element):C.Index?

It will return nil if the item is not found. You should probably use this instead of contains.

AlBlue
  • 23,254
  • 14
  • 71
  • 91