Adding objects to nsmutablearray swift

Viewed 1082

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 Answers

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"]

Related