0

I have an dataArray

struct FirebaseDataGlobal {
    let symbol: String!
}

var dataArray = [FirebaseDataGlobal]()

I need to check if this array contains a specific String. Something like below.

if dataArray.contains("string") {
  print("string found")
}

How can i do this? Can i use a function like this if the dataArray is empty?

1 Answer 1

1

Use contains(where:):

if dataArray.contains { $0.symbol == "some string" } {
    print("found one")
}
Sign up to request clarification or add additional context in comments.

2 Comments

Can this be used if the array is empty?
Sure. Give it a try.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.