0

What's the correct way of creating an array of strings, and have lots of them in a array? So far I tried this

 var arrayInArray = [[String]]()

Then I appended string arrays into "arrayInArray". And tried checking if it contained a specific string by doing

if arrayInArray[indexPath.row].containsObject(PFUser.currentUser().username)

and the error is [(String)] does not have a member named 'containsObject'. Whats the correct way of doing this?

1
  • Can you show where you "appended string arrays into 'arrayInArray'" Commented Dec 17, 2014 at 3:57

1 Answer 1

1

Use find:

var arrayInArray = [[String]]()
arrayInArray += [["Hey", "Ho"]]
arrayInArray += [["Yo", "Yeah"]]
let ix = find(arrayInArray[0], "Ho") // Optional(1), the right answer

Or contains:

let ok = contains(arrayInArray[0], "Ho") // true, the right answer
Sign up to request clarification or add additional context in comments.

4 Comments

Matt, where is "contains" documented? I didn't see that in the "The Swift Programming Language" or the "Swift Standard Library Reference". Did I just miss it?
@rdelmar There is a lot more great stuff in the Swift header than Apple has bothered to write up (so far). That's the real place to learn what you can say - and to understand how Swift built-in object types really work. To get there, say import Swift and command-click on Swift. "now the ears of my ears awake and now the eyes of my eyes are opened"
Thanks for that tip; that's great. Hopefully, Apple will get around to updating their docs soon.
@rdelmar Forgot to mention there is also some good stuff in the CoreGraphics header.

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.