Adding item to keychain using Swift

前端 未结 7 1945
栀梦
栀梦 2020-12-28 08:45

I\'m trying to add an item to the iOS keychain using Swift but can\'t figure out how to type cast properly. From WWDC 2013 session 709, given the following Objective-C code:

7条回答
  •  遥遥无期
    2020-12-28 09:30

    You simply need to downcast the literal:

    let dict = ["hi": "Pasan"] as NSDictionary
    

    Now dict is an NSDictionary. To make a mutable one, it's very similar to Objective-C:

    let mDict = dict.mutableCopy() as NSMutableDictionary
    mDict["hola"] = "Ben"
    

提交回复
热议问题