0

The code in question is a bit that comes from this answer, and checks whether a given index is available or not.

Specifically, only in XCode 8.3 does the following issue who up (the code compiles fine in XCode 9 beta. This code is also decidedly Swift 3, and not 4).

enter image description here

I looked into issues relating to the "missing argument" error, and the typical response is to make sure to include the optional argument. However, in here all 3 are included optional i, which is the type Index.

What am I doing incorrectly with the syntax here?

Nishant Bhindi
  • 2,242
  • 8
  • 21
daspianist
  • 5,336
  • 8
  • 50
  • 94

1 Answers1

1

The syntax was changed to this:

public func contains(where predicate: (Element) throws -> Bool) rethrows -> Bool

Now you should use this one

self.indices.contains(where: { (object) -> Bool in
     //make comparison here
})

Or

self.indices.contains(where: {$0 == "equal to something"})

Or you can use something like this:

if self.indices.first(where: {$0 == "equal something"}) != nil {
    return self[i]
}else{
    return nil
}

BTW, Sets are still have a bool value returned after calling "contains". Check this

Woof
  • 1,207
  • 1
  • 11
  • 21