Mujtaba
Mujtaba

Reputation: 43

Value of type 'NSMutableDictionary' has no member 'string' in swift

I am new in swift and I am getting error in xcode 12.3. Before it was working fine

my code is like this

let dictOption = options[0] as! NSMutableDictionary
 btn2.setTitle(dictOption.string(forKey: "optionValue"), for: .normal)

but it is showing error

Value of type 'NSMutableDictionary' has no member 'string'

did anyone face the similar issue.

Please help!

Upvotes: 0

Views: 928

Answers (1)

Shehata Gamal
Shehata Gamal

Reputation: 100543

Replace

dictOption.string(forKey: "optionValue")

with

dictOption.value(forKey: "optionValue")

Or more Swifty

guard let dic = options.first as? [String:Any] , 
      let value = dic["optionValue"] as? String else { return }
btn2.setTitle(value, for: .normal)

Upvotes: 0

Related Questions