learnig kid learnig kid - 6 months ago 14
Swift Question

ios Swift:How to compare object that existing in mutable array

Actually i'm new person for swift, this is my first project with swift.i have a problem faced that i cant compare the values with contains(),this is my code -- var str = "Dear"

if addstatus.contains(str) {
print("yes")
} else {
print("no")
}


For this code it suggest a error ,pls find the screenshot

enter image description here

Anyone can help me,thanks in advance :|

Answer

You can use containsObject method for checking object exist in NSMutableArray

var myArray: NSMutableArray = ["one", "two", "three"]

  if myArray.containsObject("one") {
     print("yes")
  } else {
    print("NO ")
  }
Comments