Search code examples
swiftnsarray

Extract value from __NSArrayM


I have printed the value that I want to get and is like this:

a =  Optional(<__NSArrayM 0x1704494b0>(9))

How can I extract the value 9? I wrote this but is wrong: let a = (parseJSON[index] as AnyObject).object(forKey: "subjects_count")


Solution

  • Try this:-

    guard let a = (parseJSON[index] as AnyObject).object(forKey: "subjects_count"), let value = a.first else {return}
    let stringValue = String(value)
    print(stringValue)