2

I added the string objects inside the mutablearray :

let photoArray: NSMutableArray = []
for photo in media {
    photoArray.add("\(photo.fileName ?? "")")
}

Then I get an output like:

<__NSSingleObjectArrayI 0x1c02069e0>(
  (
     "Car",
     "Dog",
     "Tree"
  )
)

But I want this :

(
     "Car",
     "Dog",
     "Tree"
)

Is there any way to get the output like that?

1
  • What do you mean by you want an output like this? Do you mean printing in console? Where is your code to print said array? Commented Oct 4, 2017 at 4:20

1 Answer 1

4

Try this, it works for me perfectly.

var photoArray = [String]()
for photo in media {
    let fileName = photo.fileName ?? ""
    print("fileName - \(fileName)")
    photoArray.append(fileName)
}
print("\n\n** photoArray - \n\(photoArray)")

result = ["Car", "Dog", "Tree"]

Sign up to request clarification or add additional context in comments.

2 Comments

I got an error Value of type '[String]' has no member 'add' at photoArray.add(fileName)
@SeizeDuh Updated now. Try again with append method.

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.