Avatar
norio_nomura 8/3/2019 10:24 AM
Dictionary.subscriptdefaultは、mutatingメンバを使うとDictionaryへ登録できる。 @swift-5.0.3 class ClassBox { var name = "" } var classDictionary = [String: ClassBox]() classDictionary["test", default: ClassBox()].name = "name" print("classDictionary:", classDictionary) struct ValueBox { var name = "" } var valueDictionary = [String: ValueBox]() valueDictionary["test", default: ValueBox()].name = "name" print("valueDictionary:", valueDictionary) (edited)