ios - Check if NSMutableArray contains a given value -
i have nsmutablearray contains string values. have string variable , want check if contained in array or not.
i tried using .contains() string say:
cannot convert value of type string expected argument type...
var mutablearray = nsmutablearray() // ["abc", "123"] var string = "abc" mutablearray.contains("abc") { // above error in line }
multiple ways check element existence in nsmutablearray. i.e
if mutablearray.contains("abc") print("found") else print("not found") or
if contains(mutablearray, "abc") print("found") or
if mutablearray.indexofobject("abc") != nsnotfound print("found") if want check existence of element according of version of swift
swift1
if let index = find(mutablearray, "abc") print(index) swift 2
if let index = mutablearray.indexof("abc") print(index)
Comments
Post a Comment