Reputation: 12656
How to convert an NSDictionary into a NSMutableDictionary in Swift?
I have a line of code regarding NSDictionary that no longer compiles in Swift 2. Please show me how to modify this line of code to bring it into compatibility with Swift 2?
let nsDict = anotherNsDictionary["amember"] as? NSDictionary
let mutableNsDict = nsDict.mutableCopy() as! NSMutableDictionary
Xcode 7.3 returns the following compile error:
Error: Ambiguous use of 'mutableCopy()'
I understand that this should probably all be changed to use a Swift Dictionary instead of NSDictionary, but major modification of this code base is not an option at this time.
Upvotes: 1
Views: 1299
Reputation: 9768
This works fine:
let nsDict = NSDictionary( object:"obj", forKey:"key" )
let mutableNsDict = nsDict.mutableCopy()
print( mutableNsDict )
Upvotes: 2