Save a tuple in NSUserDefaults

后端 未结 5 1619
梦毁少年i
梦毁少年i 2021-01-12 13:14

I\'m using a tuple to store something like this.

var accessLavels: (hasInventoryAccess: Bool, hasPayrolAccess: Bool)
accessLavels = (hasInventoryAccess: true         


        
5条回答
  •  余生分开走
    2021-01-12 13:49

    I'ts an year old question but still:

     let accesLvl : [String:AnyObject] = ["hasInventoryAcces":true, "hasPayrolAccess":false]
     NSUserDefaults.standardUserDefaults().setObject(accesLvl, forKey: "accesLevel")
    

    In case you save only bools, let accesLvl : [String:Bool] is a better option.

    In case I don't get something (I'm fairly new to Swift and programming altogether), what would be the benefit of using a "tuple" over a Dictionary, or even a struct

提交回复
热议问题