Get the string from NSMutableDictionary iOS swift

 Problem:

I had nsdictionary format of my object.I want to send the dictionary as string to server.How to convert entire dictionary into string format with accessible.

Solution:

extension NSMutableDictionary {

    func getString() -> String {

        do {

          

            let jsonData = try JSONSerialization.data(withJSONObject: self)

            if let json = String(data: jsonData, encoding: .utf8) {

                return json

            }

        } catch {

            print("something went wrong with parsing json")

        }

        return ""

    }

}


You can use the above extension to convert the dictionary to string.


Call the above function as like below


yourdic.getString()

Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

Convert NsNumber, NSDate to String in iOS Swift

Global LocationManager Singleton class iOS Swift