简体   繁体   中英

Adding objects to nsmutablearray swift

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM