How to convert string with pipes | | into dictionary

I have a string with many pipes I want to convert them into dictionary [String:Any] how can I do that ?

Example

let input = "boolFirst=false|onProject=Active|passed=false"

Into -->

let output = [String: Any] = [boolFirst: false, onProject: "Active", passed: false]

so far tried with components(separatedBy: "|") & components(separatedBy: "=")
Is there any cleaner way to achieve ?

  • You have to first use components(separatedBy:"|") and then use components(separatedBy:"=") on each of those componenta

    – 




  • @Paulw11 Request you to post as answer

    – 

Leave a Comment