Author Topic: Fixing the "contains is unavailable" error in Swift 2.0  (Read 4943 times)

kjmcneish

  • Administrator
  • *****
  • Posts: 719
    • View Profile
Fixing the "contains is unavailable" error in Swift 2.0
« on: September 11, 2015, 08:58:30 PM »
The contains() method has been removed from Swift 2.0, and has been replaced with the contains() method found on collections instead.

For example, this code in Swift 1.2 and earlier:

Code: [Select]
let fruit = ["Apple","Orange","Banana"]
let hasApple = contains(fruit, "Apple")

Should be changed to:

Code: [Select]
let fruit = ["Apple","Orange","Banana"]
let hasApple = fruit.contains("Apple")

All the best!
Kevin McNeish
Author of Learn to Code in Swift: https://itunes.apple.com/us/book/learn-to-code-in-swift/id942956811?mt=11
Check out our Robot Tic-Tac-Toe app: https://itunes.apple.com/us/app/robot-tic-tac-toe/id990638517?mt=8
« Last Edit: November 15, 2015, 10:12:46 AM by kjmcneish »